[英]What is the equivalent html attribute of KnockoutJs's WITH in AngularJs
我目前使用AngularJs和我在過去使用KnockoutJs,我想用類似的屬性KnockoutJs的with
屬性,但似乎無法找到我要找的。 我的AngularJs $ scope目前看起來像這樣
$scope.data = {
selectedCountry: ...,
...
};
nowChountry是一個JS對象,在HTML中我希望能夠做到這樣的事情
<div with="data.selectedCountry">
<div ng-bind="name"/>
<div ng-bind="prop1"/>
<div ng-bind="prop2"/>
<div>
而不是必須要做我目前正在做的事情
<div>
<div ng-bind="data.selectedCountry.name"/>
<div ng-bind="data.selectedCountry.prop2"/>
<div ng-bind="data.selectedCountry.prop3"/>
<div>
有沒有辦法在AngularJs中做到這一點? 任何幫助將非常感激。 謝謝。
最接近的是ng-init
指令。
<div ng-init="c = data.selectedCountry">
<div ng-bind="c.name"></div>
<div ng-bind="c.prop1"></div>
<div ng-bind="c.prop2"></div>
</div>
盡管它與Knockout(不需要別名)並不完全相同,但是它應該使您的生活更輕松,因為別名比編寫完整的導航屬性路徑更好。
我已經搜索了很多。 我找到的不僅僅是一個技巧:
您可以通過以下方式模擬此功能:
<div ng-repeat="item in [data.selectedCountry]">
<div ng-bind="name"/>
<div ng-bind="prop2"/>
<div ng-bind="prop3"/>
<div>
TG。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.