【问题标题】:Is there a way to break into the debugger when an AngularJS expression is running?当 AngularJS 表达式运行时,有没有办法闯入调试器?
【发布时间】:2018-03-28 14:59:10
【问题描述】:
如果我有这个选择:<select name="custType" ng-model="vm.custType" ng-options="c.name.toUpperCase() as c.name for c in vm.customers"...>
有没有办法在 ng-options 中的表达式开始运行时闯入 devtools 调试器?
不同的原因:
- 我想知道表达式在网页的生命周期中何时运行。
- 我想知道 c.name 和 vm.customers 的当前值
表达式生命周期中的某个时间点。
- 我还想知道在加载数据之前是否正在使用 vm.customers。
【问题讨论】:
标签:
angularjs
google-chrome-devtools
【解决方案1】:
尝试使用以下方法:
HTML
<select name="custType"
ng-model="vm.custType"
ng-options="c.name.toUpperCase() as c.name for debugCustomer(c) in vm.customers"
... ></select>
JS
...
$scope.debugCustomer = function (customer) {
console.log(customer);
debugger;
return customer;
}
...
【解决方案2】:
在 angular src 代码中找到 ng-options 指令并放置一个断点。
ng-options