0

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://jsfiddle.net/z6bfC/

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!

4

1 回答 1

1

It seems the AngularJS 1.1.0 does some funky stuff.

Try 1.1.1. http://code.angularjs.org/1.1.1/angular.min.js

于 2013-08-29T21:14:54.937 回答