在 Handlebars 中,您可以更改当前范围,因此如果您有一个对象:
walrus: {
bubbles: 7,
zombies[
{name: 'Jim', hobby: 'pinocle'},
{name: 'Cassandra', hobby: 'privateering'},
{name: 'Ke$ha', hobby: 'yelling'}
],
address: {
city: 'Fresno',
state: 'CA'
}
}
然后我可以将该上下文发送到这样的模板:
<article class='walrus'>
<h2>I have {{ bubbles }} bubbles!</h2>
<ul>
{{#each zombies}}
<li>{{ name }} likes {{ hobby }}
{{/each }}
</ul>
<div class='address'>
{{#with address}}
<p>{{city}}, {{state}}</p>
{{/with}}
</div>
</article>
但在 Angular 中,如果我设置 $scope.walrus = walrus,我会得到以下结果:
<article class='walrus'>
<h2>I have {{ walrus.bubbles }} bubbles!</h2>
<ul>
<li ng-repeat="zombie in walrus.zombies">{{ zombie.name }} likes {{ zombie.hobby }}
</ul>
<div class='address'>
<p>{{walrus.address.city}}, {{walrus.address.state}}</p>
</div>
</article>
有没有办法让 Angular 识别它所在的范围,而不需要额外的walrus.
, zombie.
, or (worst of all) walrus.address.
?