It seems the AngularJS 1.1.0 does some funky stuff.
In jsFiddle, why do I have to click twice to change the text in directive?
-
26-06-2022 - |
Question
I have same directive's example in jsFiddle and another one in plnkr. In jsFiddle, I have to click the text twice to change the text while in plnkr it works like expected with one . Can someone point it out if this is an expected behavior or just a bug in fiddle.
http://plnkr.co/edit/2Z1u2PzbRzPYzjPv4miG?p=preview
HTML:
<div ng-app="testModule">
<div ng-controller="MyCtrl">
<div>{{test}}
<br/>
<test-directive class="width" bindme="test" style="color: red;">Click Me Twice!!</test-directive>
</div>
</div>
</div>
Directive/Controller:
angular.module('testModule', []).directive('testDirective', function () {
return {
restrict: 'E',
scope: {
bindme: "="
},
link: function (scope, element, attr) {
element.bind('click', function () {
scope.bindme = "Changed";
if (!scope.$$phase) {
console.log(scope.bindme);
scope.$apply();
} else {
console.log("Something");
}
});
}
};
}).
controller('MyCtrl', function ($scope) {
$scope.test = "Some string";
});
Thanks!
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow