无法从指令中访问ngModel

时间:2014-07-13 18:58:27

标签: angularjs directive angularjs-ng-model

请给我一些懈怠,这是我的第一篇文章,因为我对角度很新。 我正在尝试实现一个指令来验证帐户名是否存在。

虽然我一直在使用这种指令(并将它用于多种用途),但我遇到了一个令人兴奋的showstopper =(。

该指令是从包含ngModel的输入标记触发的。 这是我的部分指令:

app.directive('organizationValidate', function (dataFactory) {
return {
    require: 'ngModel',
    link: function ($scope, $element, $attrs, $ctrl) {
        $ctrl.$parsers.push(function (viewValue) {
            $ctrl.$setValidity('organizationValidate', true);
            if ($ctrl.$valid) {
                $ctrl.$setValidity('checkingOrganization', false);
                console.log("Got the Direc");

这是我的HTML输入:

<input type="text" data-organization-validate class="form-control" ng-model="newOrg.OrganizationName">

在尝试从指令中访问$ scope.newOrg.OrganizationName时,我得到newOrg undefined ...... :(

有什么建议吗?

谢谢!

0 个答案:

没有答案
相关问题