angular.js - angularjs directive link append problem
ringa_lee
ringa_lee 2017-05-15 17:03:31
0
1
478
<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();
                });
            }

The current problem is very strange. The ng-click event will automatically trigger apply. However, the state of scope.show in choiceme() has indeed changed, but it is not synchronized to the Dom. Please ask for advice on this issue.

ringa_lee
ringa_lee

ringa_lee

reply all(1)
習慣沉默

Look at your code, is it triggered when you click p标签的时候,应该scope.choicemeelem.find("p").on("click"?

Is this reasonable?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template