我想根据控制器内属性的值显示元素。
eReaderBook.directive("controlTools", function () {
return {
replace : true,
restrict : "E",
templateUrl : "assets/directives/controlstools.html",
controller : function ($scope) {
$scope.visible = false;
},
link : function (scope, el, attr) {
el.bind("mouseover",function()
{
console.log(scope.visible)
scope.visible = true;
});
el.bind("mouseout",function()
{
console.log(scope.visible)
scope.visible = false;
})
}
};
});
<div class="menuitem"><span class="glyphicon glyphicon-search"></span><span ng-show="visible" class="menutext">Toc</span></div>
在指令中,我有一个用$scope.visible = false
定义的控制器。页面加载时一切正常。我想将状态更改为$scope.visible = true
上的mouseover
和$scope.visible = false
上的mouseout
。为什么scope.visible = true;
不会影响ng-show
?
答案 0 :(得分:0)
You just forgot to add scope: true that is responsible to share scope.
return {
replace: true,
restrict: "E",
scope: true,
templateUrl: "assets/directives/controlstools.html",