angular.module("myDirective",[])
.directive("tabOne",function (){
return{
restrict:"E",
replace:true,
scope:{
data:"=myData",
},
transclude:true,
template:' <p ng-hide="show">'+
'<p ng-repeat="x in data">'+
'{{x}}'+
'</p>'+
'</p>',
link:function(scope,elem,attr){
scope.show=true;
elem.find("p").on("click",function(){
scope.show=!scope.show;
console.log(scope.show);
});
}
}
})
As shown in the question, I am now creating a variable show in the link. This show is used in the template to indicate whether hide or scope.show always displays true?
I don’t know where the problem lies, please give me some advice! Thank you
But console.log (scope.show) changes synchronously
Changed:
Added:
See the documentation
Document address: scope
Thank you for the advice. After reading the documentation, many of my own methods will trigger apply, dom, and the exhaustive settimeout operation will not trigger apply