调试通过ng-init进行的双向绑定不工作

Debugging a two way binding through an ng-init not working

本文关键字:绑定 工作 ng-init 调试      更新时间:2023-09-26

我怎么能console.log一个变量{{scope}}ng-init调试2方式绑定/范围从视图?

html:

<div ng-init="omg({{svglayout(key).width}})"></div>

js:

$scope.omg = function(evt) {
   console.log(evt);
};

我知道有很多其他的方法来做到这一点,但我试图确保数据是适当的范围从标记,它不是试点错误…

通过使用console.log,我可以更容易地测试标记,因为有很多固定位置元素。

更新:如果我删除插值没有错误抛出,但它出现了undefined对象不是未定义的,因为我知道如果我输入

<p style="position: absolute; z-index: 99999; top:0; left:0; height: 500px; width: 500px background: #fff;">{{svglayout(key)}}</p>

这有结果:

{"width":707.912457912458}

和svlayout函数:

scope.svglayout = function(idx) {
  var newWidth = (scope.windowHeight-clearanceSetter)*      (scope.adPageData.pages[idx].imagewidth/scope.adPageData.pages[idx].imageheight);
  return {
      width: newWidth
  }
};

尝试删除字符串插值

omg(svglayout(key).width)