不是从compilefunction叫anglarjs指令链接功能 [英] anglarjs directive link function not called from compilefunction

查看:93
本文介绍了不是从compilefunction叫anglarjs指令链接功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要访问的ngModelController在链接功能。
我使用$编译生成动态地根据用户选择的HTML。
按照该文档我需要从compileFunction返回链接功能。

I want to access the ngModelController in the linking function. I am using $compile to generate the html dynamically based on the user options. as per the docs i need to return the linking function from compileFunction.

,但连接功能是没有得到调用。
Plunker链接

but the linking function is not getting called. Plunker Link

我试图进入字母限制用户在键入=数量。

i am trying to restrict user from entering alphabets when type=number.

修改

var compileFunction = function (element) {
        return function (scope, telem, tattr, ngModelCtrl) {
            console.log(ngModel);
            var template = helper.getFieldHtml(fieldHtml, scope.options);
            element.html(template);
            $compile(element.contents())(scope);
            return linkFunction.apply(scope, telem, tattr, ngModel);
        };
    };

return {
        scope: { options: '=', ngModel: '=' },
        required: ['ngModel', '^form'],
        restrict: 'E',
        compile: compileFunction
    };

如何我访问ngModelCtrl在链接功能..从编译函数返回

how to I access ngModelCtrl in the link function.. returned from compile function

推荐答案

您只需要更换规定,而不是必需的

You just need to replace "require" instead of "required"

 return {
            scope: { options: '=', ngModel: '=' },
            require: ['ngModel', '^form'],
            restrict: 'E',
            compile: compileFunction
        };

它的工作。

这篇关于不是从compilefunction叫anglarjs指令链接功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆