Cod*_*ein 5 variables scope angularjs
在我的Angular项目中,我使用的是一个特定的值,在我的控制器中被称为:
$scope.feature1.items.thisItem
<div>在我看来,有一个特别的用途是thisItem多次使用它并且引用它是非常混乱的{{feature1.items.thisItem}},例如:
<div id="{{feature1.items.thisItem}}header>
<h1> You've reached the section about {{feature1.items.thisItem}} </h1>
</div>
Run Code Online (Sandbox Code Playgroud)
有没有办法在视图中重命名此变量?我想简单地称之为one.我试过{{feature1.items.thisItem as one}}但是没用.还有其他想法吗?
是! ng-init是为此目的而设计的 - 别名另一个变量:
<div ng-init="thisItem = feature1.items.thisItem">
<h1> You've reached the section about {{thisItem}} </h1>
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3053 次 |
| 最近记录: |