当我们点击任何列表元素时,我需要更改范围值并触发onclick函数。
但是在这个代码中,当我们为list元素添加标签时,ng-click不起作用。
代码如下,
<ul class="" id="filter" path="filter">
<li value="popular" id="popular" data-faculty="Popular" class="item" onclick="SortByFilter(this, 'smartphone');" ng-click="Mobilebidirectionalsort = !Mobilebidirectionalsort"><label for="Popular">Popular</label><span class="btnSort"><input type="radio" id="Popular" name="filterOptions" class="btnRadio"></span></li>
<li value="newest" id="newest" data-faculty="High Rating" class="item" onclick="SortByFilter(this, 'smartphone');" ng-click="Mobilebidirectionalsort = !Mobilebidirectionalsort"><label for="High Rating">High Rating</label><span class="btnSort"><input type="radio" id="High Rating" name="filterOptions" class="btnRadio"></span></li>
</ul>
答案 0 :(得分:0)
它应该工作正常。我已经创建了您上面描述的情况的镜像,您可以清楚地看到ng-click
如何改变Mobilebidirectionalsort
的价值
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
</head>
<body ng-controller="myCtrl">
<div class="col-sm-7 nopadding doc-att">
Mobilebidirectionalsort value : {{Mobilebidirectionalsort}}
<ul class="" id="filter" path="filter">
<li value="popular" id="popular" data-faculty="Popular" class="item" onclick="SortByFilter(this, 'smartphone');" ng-click="Mobilebidirectionalsort = !Mobilebidirectionalsort">
<label for="Popular">Popular</label><span class="btnSort"><input type="radio" id="Popular" name="filterOptions" class="btnRadio"></span>
</li>
<li value="newest" id="newest" data-faculty="High Rating" class="item" onclick="SortByFilter(this, 'smartphone');" ng-click="Mobilebidirectionalsort = !Mobilebidirectionalsort">
<label for="High Rating">High Rating</label><span class="btnSort"><input type="radio" id="High Rating" name="filterOptions" class="btnRadio"></span>
</li>
</ul>
<script>
var myApp = angular.module("myApp", []);
myApp.controller("myCtrl", ['$scope', function($scope) {
$scope.Mobilebidirectionalsort = true;
}]);
function SortByFilter(attr1, attr2) {
console.log('SortByFilter called');
}
</script>
</body>
</html>
&#13;