angular.js - angularjs 指令link 追加问题
ringa_lee
ringa_lee 2017-05-15 17:03:31
0
1
463
<p class="tab">
    <p ng-transclude class="click" ></p>
    <i class="iconfont" ng-show="show">X</i>
    <i class="iconfont" ng-show="show1">Y</i>
    <p ng-hide="show">
        <p ng-repeat="x in data" ng-click="choiceme(x)">
            {{x}}
        </p>
    </p>
</p>
link:function(scope,elem,attr){
                scope.show=true;
                scope.show1=false;
             
                scope.choiceme=function (i){
                    
                    console.log(scope.show,scope.show1);
                    scope.show1=!scope.show1;
                    scope.show =!scope.show;
                    console.log(scope.show,scope.show1);
                };
                  elem.find("p").on("click",function(){{
                    scope.show=!scope.show;
                          console.log(scope.show,scope.show1);
                    scope.$apply();
                });
            }

现在的问题出现的很诡异就是ng-click事件会自动触发apply可是choiceme()中scope.show的状态的确是变化了可是没有同步到Dom中这个问题请教了

ringa_lee
ringa_lee

ringa_lee

membalas semua(1)
習慣沉默

Melihat kod anda, apabila anda mengklik teg p, kedua-dua scope.choiceme dan elem.find("p").on("click" harus dicetuskan, bukan?

Adakah ini munasabah?

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan