为什么我的指令中的ctrl为null?

时间:2015-10-25 06:29:42

标签: angularjs directive angular-ngmodel angular-directive

我有这样的指示,但为什么参数 ctrl null

标记:

<test ng-name="htest" ng-family="hfamily" ></test>

指令:

 var tmp = "<input   type='text' ng-model='htest' >";

return {
    restrict: 'AE',
    template: tmp,
    require: "^?ngModel",
    scope: {
        name: "=ngName",
        family:"=ngFamily"
    },
    link: function (scope, element, attrs, ctrl) {
        console.log("aaaaaaaaaaaaaaa", ctrl);

    }
}

1 个答案:

答案 0 :(得分:3)

你必须插入ng-model =&#39; htest&#39;在第一个html标签中,如

<test ng-name="htest" ng-family="hfamily" ng-model='htest'></test>