modalinstance注入视图模型进行更新

时间:2016-10-10 05:50:45

标签: javascript angularjs angular-ui-bootstrap bootstrap-modal

我正在使用Modal弹出窗口列出帐户详细信息(accno和name)。一旦从列表视图中选择行模型变量(vm.vismaDebitAccount)需要更新哪个是动态的。在实际情况下,弹出窗口将在文本框onclick上打开,一旦从弹出窗口中选择了行,相关的文本框文本应该用帐户名称更新。视图模型变量(特定的文本框绑定)应该能够在没有硬连接的情况下注入modalinstance结果。

这是我的代码。

我的问题是为什么vm.vismaDebitAccount没有获得更新?请帮帮我。

这是UI绑定的地方



 <tr ng-repeat="accEntry in vm.vismaAccEntries">
            <td>{{accEntry.invoiceNo}}</td>
            <td><input type="text" ng-model='accEntry.debitAccNo' required name="field" ng-click="vm.openVismaAccModal('debit')" /></td>
            <td><input type="text" ng-model='accEntry.debitVat' required name="field" /></td>
            <td><input type="text" ng-model='accEntry.creditAccNo' required name="field" ng-click="vm.openVismaAccModal('credit')"/></td>
            <td><input type="text" ng-model='accEntry.creditVat' required name="field" /></td>
            <td>{{accEntry.amount}}</td>
            <td>{{accEntry.voucherDate}}</td>
            <td>{{accEntry.dueDate}}</td>
&#13;
&#13;
&#13;

&#13;
&#13;
app.controller('invoiceCodeController', ['$routeParams', 'invoiceService', 'vismaService', '$uibModal', '$log', function ($routeParams, invoiceService, vismaService, $uibModal, $log) {
    var vm = this;
    var vismaDebitAccount = {
        catogory: '',
        account: ''
    }
    var vismaCreditAccount = {
        catogory: '',
        account: ''
    }

     vm.openVismaAccModal = function (accountType) {
    console.log('hi before')
    var modalInstance = $uibModal.open({
        templateUrl: 'accountPopup.html',
        controller: 'vismaAccController as vm'
    });

    modalInstance.result.then(function (selectedAccount) {
        if (accountType === 'debit') {
            vm.vismaAccEntries[0].debitAccNo = selectedAccount.account.No;
        }

        if (accountType === 'credit') {
            vm.vismaAccEntries[0].creditAccNo = selectedAccount.account.No;
        }
        
    }, function () {
        $log.info('Modal dismissed at: ' + new Date());
    });

}

}]);
&#13;
&#13;
&#13;

&#13;
&#13;
app.controller('vismaAccController', ['vismaService', '$uibModalInstance', function (vismaService, $uibModalInstance) {

    var vm = this;
    var selectedAcc = {
        category: '',
        account: ''
    };

    Init();

    function Init() {
        getVismaAccData();
    }

    vm.tabChange = function (e) {
        if (e.target.nodeName === 'A') {
            e.preventDefault();
        }
    }

    vm.rowSelect = function (index, debitAcc, flag) {

        selectedAcc.category = flag;
        selectedAcc.account = debitAcc;

    }

    vm.ok = function () {
        $uibModalInstance.close(selectedAcc);
    };

    vm.cancel = function () {
        $uibModalInstance.dismiss('cancel');
    };

    function getVismaAccData() {
        var errors = [];
        vismaService.getSuppliers().then(function (data) {
            vm.vismaSuppliers = data;
        },
            function (errorMsg) {
                errors.push('<li>' + errorMsg + '</li>');
                vm.savedSuccessfully = false;
            });

        vismaService.getCustomers()
            .then(function (data) {
                vm.vismaCustomers = data;
            },
            function (errorMsg) {
                errors.push('<li>' + errorMsg + '</li>');
                vm.savedSuccessfully = false;
            });

        vismaService.getGeneralLedger()
            .then(function (data) {
                vm.vismaGL = data;
            },
            function (errorMsg) {
                errors.push('<li>' + errorMsg + '</li>');
                vm.savedSuccessfully = false;
            });

        if (errors.length > 0) {
            vm.message = errors.join(' ');
        }
    }
}]);
&#13;
&#13;
&#13;

0 个答案:

没有答案