Вопрос

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!

Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top