我正在尝试在我的列表中插入ng-click。但它不起作用。我尝试在li元素上使用ng-repeat和不使用ng-repeat。
HTML代码为:
<ul class="nav nav-tabs">
<li role="presentation" class="active"><a href="#" ng-click="changeRoute()">Home</a></li>
<li role="presentation"><a href="#">About Us</a></li>
<li role="presentation"><a href="#">Products</a></li>
<li role="presentation"><a href="#">Customer Feedback</a></li>
<li role="presentation"><a href="#">Contact Us</a></li>
</ul>
这是控制器:
$scope.changeRoute = function() {
console.log('Test');
}
答案 0 :(得分:1)
如果你真的想要,你可以做这样的事情。
<ul class="nav nav-tabs">
<li role="presentation" class="active"><a href="#" ng-click="changeRoute('Home')">Home</a></li>
<li role="presentation"><a href="#" ng-click="changeRoute('About Us')">About Us</a></li>
<li role="presentation"><a href="#" ng-click="changeRoute('Products')">Products</a></li>
<li role="presentation"><a href="#" ng-click="changeRoute('Customer Feedback')">Customer Feedback</a></li>
<li role="presentation"><a href="#" ng-click="changeRoute('Contact Us')">Contact Us</a></li>
</ul>
$scope.changeRoute = function(route) {
//handle route here
}
但是仅仅将链接放在href
s中,而不是ng-repeat
是否有问题?