2
因此,当我将鼠标悬停在锚标签上时,iconVisible变量会更新,但视图不会即使它的计算结果为true,我也可以看到使用Inspector?任何人都知道如何解决这个问题似乎很容易,但它已经困扰了我好几个小时。AngularJS视图不会在ng-show中更新指令
注:我试图完成的是onmouseover链接图标显示,但我已经剥离了不必要的东西。
angular.module('App.header', [])
.controller('HeaderController', function ($scope) {
})
.directive('menu', function() {
return {
restrict:'EA',
replace:true,
transclude:true,
template:'<ul ng-transclude></ul>',
scope:{
},
link: function (scope, el, attr) {
}
}
})
.directive('menuItem', function() {
return {
restrict:'EA',
replace:true,
transclude:true,
template:'<li><a href="#" ng-transclude ng-mouseover="showIcon()"></a><img src="#" alt="" ng-show="{{iconVisible}}"/></li>',
controller: function ($scope) {
$scope.iconVisible = false;
},
scope:{
},
link: function (scope, el, attr) {
scope.showIcon = function() {
scope.iconVisible = !scope.iconVisible;
}
}
}
})
<header class="container" ng-controller="HeaderController">
<menu>
<menu-item>Home</menu-item>
</menu>
你能在Fiddle或Plunker中重现这种行为吗? – 2014-11-02 09:56:47
当然!http://jsfiddle.net/jpsk61bc/ – 2014-11-02 10:00:42
不能正常工作......你在小提琴里得到了很多控制台错误 – 2014-11-02 10:04:18