我是AngularJS的新手,我尝试使用ng-repeat
编写代码,但由于我需要将角度表达式传递给函数而卡住,但无法使用,这是我的代码:
HTML代码
<div ng-controller="Profile as pro">
<ul class="nav nav-tabs">
<li ng-repeat="tabs in tabArray"
ng-class="{active: pro.tab==1}"
ng-click=" pro.setTab({{tabs.value}})">
<a href="">{{tabs.name}}</a>
</li>
</ul>
<div>
控制器代码
controller.controller('Profile', ['$scope',function ($scope) {
$scope.tabArray = [
{name:"Profile","value":1},
{name:"Education","value":2},
{name:"Work","value":3},
{name:"About","value":4}
];
this.tab=1;
this.setTab = function(tabSelected){
this.tab=tabSelected;
};
}]);
最佳答案
您的代码中唯一的问题是在以下行中:
ng-click=" pro.setTab({{tabs.value}})" // don't use {{ and }} thing here, it is not needed
以下代码是固定版本:
ng-click="pro.setTab(tabs.value)" // only {{ and }} are removed and it works well
快乐的帮助!
关于javascript - 将 Angular 表达式传递给函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35669888/