2014-11-02 48 views
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> 

+0

你能在Fiddle或Plunker中重現這種行爲嗎? – 2014-11-02 09:56:47

+0

當然!http://jsfiddle.net/jpsk61bc/ – 2014-11-02 10:00:42

+0

不能正常工作......你在小提琴裏得到了很多控制檯錯誤 – 2014-11-02 10:04:18

回答

5

ng-show="iconVisible"

基本上取代ng-show="{{iconVisible}}"你寫皈依

NG秀= 「真」

並給予什麼$ scope.true是未定義,ng-show不顯示元素

+0

非常感謝! – 2015-03-22 07:25:08

相關問題