Cra*_*igM 2 javascript web angularjs knockout.js
我目前正在使用AngularJs,而且我过去曾使用过KnockoutJs,我想使用与KnockoutJs with属性类似的属性,但似乎无法找到我正在寻找的东西.我的AngularJs $ scope目前看起来像这样
$scope.data = {
selectedCountry: ...,
...
};
Run Code Online (Sandbox Code Playgroud)
nowChountry是一个JS对象,在HTML中我希望能够做到这样的事情
<div with="data.selectedCountry">
<div ng-bind="name"/>
<div ng-bind="prop1"/>
<div ng-bind="prop2"/>
<div>
Run Code Online (Sandbox Code Playgroud)
而不是必须做我正在做的事情,这是
<div>
<div ng-bind="data.selectedCountry.name"/>
<div ng-bind="data.selectedCountry.prop2"/>
<div ng-bind="data.selectedCountry.prop3"/>
<div>
Run Code Online (Sandbox Code Playgroud)
有没有办法在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>
Run Code Online (Sandbox Code Playgroud)
虽然它与Knockout(你不需要别名)不完全相同,但它应该让你的生活更轻松,因为别名比编写完整的导航属性路径更好.