我刚刚从KnockoutJS切换到AngularJS,但在AngularJS中找不到KnockoutJS的“ with”数据绑定。
这是KnockoutJS中的代码片段。“ with”绑定创建一个新的绑定上下文,以便将后代元素绑定到指定对象的上下文中。
<h1 data-bind="text: city"> </h1> <p data-bind="with: coords"> Latitude: <span data-bind="text: latitude"> </span>, Longitude: <span data-bind="text: longitude"> </span> </p> <script type="text/javascript"> ko.applyBindings({ city: "London", coords: { latitude: 51.5001524, longitude: -0.1262362 } }); </script>
AngularJS是否有类似上下文的内容?
我所不知道的..这是我能做的最好的事情:
<h1>{{city}}</h1> <p ng-repeat="c in [coords.or.possibly.deeper.in.tree]"> Latitude: {{c.latitude}}, Longitude: {{c.longitude}} </p>