如何将ng-model绑定到指令的范围

时间:2016-08-08 15:59:19

标签: javascript angularjs

我对绑定ng-model感到困惑,这是在指令的模板html里面的

<input type="file" ng-model="uimg" value="TEST"/>

<button ng-click="Upload(user,uimg)"
        class="btn btn-default btn-sm">
    <span class="glyphicon glyphicon-upload"></span>
</button>

如你所见,我有一个名为“uimg”的ng模型,但当我点击按钮时,函数调用此代码

这是我写的指令类

导出类CustomDirective实现了ng.IDirective {

    public controller: any;
    public restrict: string;
    public templateUrl: string;
    public scope: Object;
    public link:ng.IDirectiveLinkFn;
    public transclude:boolean;

    constructor(restrict: string,
        scope: Object ,
        controller: any,
        templateUrl: string,
        link:any
    ) {

        this.restrict = restrict;
        this.controller = controller;
        this.templateUrl = templateUrl;
        this.scope = scope;
        this.link = link;
        this.transclude = true;

    }

}

我将指令注册到应用程序。

app.directive("uploadKimlik",
() => new Application.Directive.CustomDirective("A",
    { user: "=",uimg:"=" },
    "",
    Application.Helper.Generic.GetPath() + "admin/GetHtml/?id=upload",
    (scope) => {
        scope.Upload=(u,i)=> {
            alert("u john");
            console.log(scope.user);
            console.log(i);
        };
    }));

第一次警报工作并提醒“你好约” 第二个console.log(scope.user)也可以,但我在指令中创建的ng-model返回undefined。

我无法理解的错误。

任何帮助将不胜感激。 感谢。

0 个答案:

没有答案