如何在AngularJS中调试此控制器?

时间:2017-12-26 10:05:53

标签: javascript angularjs

我的HTML如下:

                    <div class="col-md-4">{{ctrl.serviceInstance.additionalPorts}}<span
                            ng-if="ctrl.serviceInstanceOfActiveDeployment != null && !ctrl.compareArrays(ctrl.serviceInstanceOfActiveDeployment.additionalPorts,ctrl.serviceInstance.additionalPorts)"
                            class="glyphicon glyphicon-alert alert-icon"
                            uib-tooltip-html="'Active Deployment has a different set of Additional Ports.'"></span>
                    </div>

并且,控制器定义为:

function _compareArrays(arr1,arr2){
    if (arr1 === null && arr2 === null)
        return true;
    if (arr1 != null && arr2 != null) {
        arr1.sort();
        arr2.sort();
        var result = arr1.length == arr2.length && arr1.every(function(element, index) {
                return element === arr2[index];
            });
        return result;
    }
    return false;
}

我想检查哪些值传递给变量arr1&amp; arr2。代码在我的浏览器中缩小了,我无法直接在浏览器的控制台中访问变量。我怎样才能访问这些?

谢谢!

2 个答案:

答案 0 :(得分:1)

我一直在使用ng-inspector来获取控制器范围的值,它提供了一个非常好的树代表视图。

答案 1 :(得分:1)

&#13;
&#13;
function _compareArrays(arr1, arr2) {
  console.log('this is arr1' + arr1);
  console.log('this is arr2' + arr2);
  if (arr1 === null && arr2 === null)
    return true;
  if (arr1 != null && arr2 != null) {
    arr1.sort();
    arr2.sort();
    var result = arr1.length == arr2.length && arr1.every(function(element, index) {
      return element === arr2[index];
    });
    return result;
  }
  return false;
}
&#13;
&#13;
&#13;

应该使用如上所述的console.log语句来完成