angularJS - 我的指令链接未被调用

时间:2017-05-15 03:08:12

标签: angularjs angular-directive

我正在使用角度应用创建新指令。我的指令链接由于某种原因未被调用。请帮助我吗?

我的指示:<data-grid data=slideView.pages ></data-grid>

我的代码:

"use strict";

( function() {

var dataGridMaker = function( ) {

    return {
        scope: true, 
        replace: true,
        template:"<h1>Testing</h1>",
        link: function( ) {
            console.log(" Hi there!!");//not calling
        }
    }

}

angular.module( "gridDataApp.directives", [] )
.directive( "dataGrid", dataGridMaker );

} ( ));

1 个答案:

答案 0 :(得分:1)

您的指令将无法识别,因为HTML5已经有datagrid元素。尝试将其名称更改为另一个名称。

"use strict";

( function() {

var dataGridMaker = function( ) {

    return {
        scope: true, 
        replace: true,
        template:"<h1>Testing</h1>",
        link: function( ) {
            console.log(" Hi there!!");//not calling
        }
    }

}

angular.module( "gridDataApp.directives", [] )
.directive( "sampleGrid", dataGridMaker );

} ( ));
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<div ng-app="gridDataApp.directives">
  <div sample-grid></div>
</div>