0
我有这样的指令:再用对象参考
app.directive("myData", function() {
return {
restrict: "E",
templateUrl: "myTemplate.html"
};
});
在myTemplate.html
然后,我有这样的:
<input type="number"
ng-if="(getMyObject(item.DataId)).Valid"
ng-model="(getMyObject(item.DataId)).Price"/>
<div ng-bind="(getMyObject(item.DataId)).Price"
ng-if="!(getMyObject(item.DataId).Valid"></div>
该指令被置于ng-repeat
内(因此item.
)。
我的问题是如何将我从getMyObject()
得到的对象存储在某处,因此我不必重复调用它。我试图用ng-init
为:
<p ng-init="dataObject=getMyObject(item.DataId)"/>
,并引用它想:
<input type="number"
ng-if="dataObject.Valid"
ng-model="dataObject.Price"/>
<div ng-bind="dataObject.Price"
ng-if="!dataObject.Valid"></div>
但是,一旦我提出的任何变化,这并不工作,改变数据模型,因为ng-init
仅适用于第一次加载页面时。
什么是getMyObject发生这样的,如果你反复调用它,它事项?如果你需要一个表达式来确定你绑定或在ng-if中使用什么。如果您多次拨打该功能,这有什么关系 – jw56578 2015-02-17 21:13:57
对不起,我没有解释得很好。因为这个页面非常大,我嵌套了ng-repeat,所以我试图为了性能原因优化代码。 – notlkk 2015-02-17 21:33:52