AngularJS从指令更新模型

时间:2017-04-01 18:29:06

标签: jquery angularjs directive jquery-steps

我有一个Angular指令,它显示了用户能够修改和更新的帐户详细信息。我在指令中使用link函数在渲染指令后触发一些javascript。

我的问题是当用户修改input中的值时,基本模型directiveShippingAccount不会反映更新。

如何将任何更新绑定回directiveShippingAccount模型,以便我可以保存更新的值?

以下是主HTML页面中的指令

<account-wizard directive-shipping-account="shippingAccount"
                        directive-bind-account-directive="bindAccountDirective()"
                        directive-save-shipping-account="saveShippingAccount(a)">
</account-wizard>

以下是我的HTML模板中account-wizard指令

的摘录
<div class="row">
    <h2>Please enter your details below</h2>
    <div class="col-lg-4 col-lg-offset-4 ">
    <input type="text" class="text-center form-control required" ng-model="directiveShippingAccount.CollectionAddress.company" placeholder="Company name" value="{{directiveShippingAccount.company}}" />
        <input type="text" class="text-center form-control required" ng-model="directiveShippingAccount.ShippingAccountNumber" placeholder="Royal Mail Account Number" value="{{directiveShippingAccount.ShippingAccountNumber}}" />
        <input type="text" class="text-center form-control required" ng-model="directiveShippingAccount.AllowedNDCodes" placeholder="Service Codes" value="{{directiveShippingAccount.AllowedNDCodes}}" />
    </div>
</div>

这是指令本身

labulo.directive('accountWizard', function ($timeout) {
    return {
        templateUrl: '../Scripts/angular/directives/templates/AccountWizard.html',
        replace: true,
        scope: {
            directiveShippingAccount: "=",
            directiveBindAccountDirective: "&",
            directiveSaveShippingAccount: "&"
        },
        link: function (scope, elem, attr) {
            $timeout(function () {
                scope.directiveBindAccountDirective();
            });
        }
    }
});

0 个答案:

没有答案