AngularJS Link function not called

前端 未结 4 1127
一整个雨季
一整个雨季 2021-01-04 04:18

I\'m trying to write my first AngularJS directive: one involving the link function. The directive is being loaded, but when I use it in my page the link<

4条回答
  •  臣服心动
    2021-01-04 04:55

    The default for angular is to assume that directives are attributes, not elements! You are using a directive as an element so you need to specify this with the restrict. The updated code reads:

    appModule.directive('googleMapsSymbol', function () {
        console.log("Directive was run");
        return {
            restrict: 'E',
            link: function (scope, elem, attrs) {
                console.log("Link was called");
            }
        };
    });
    

    Note the restrict: 'E',. Best of luck!

    Updating your fiddle: http://jsfiddle.net/j8ZZ4/

提交回复
热议问题