Angular指令不显示任何值(Angular directive not displaying any values)

编程入门 行业动态 更新时间:2024-10-25 00:30:30
Angular指令不显示任何值(Angular directive not displaying any values)

我有这个没有显示任何值的指令,即使在我打破函数时,vm变量在创建每个指令行时都有。

(function () { angular .module('sales.directives') .directive("viewPayment", viewPayment); function viewPayment() { return { controller: 'ViewPaymentController', controllerAs: 'vm', bindToController: true, templateUrl: 'pages/viewPayment.html', restrict: 'E', scope: { payment: '=', paymentDetails: '=', setCurrentPayment: '&', currentPaymentId: '=', openLineItemDrawer: '&' } }; } angular .module('sales') .controller('ViewPaymentController', viewPaymentController); viewPaymentController.$inject = ['$scope']; function viewPaymentController($scope) { var vm = $scope; vm.details = _(vm.paymentDetails).where({ 'paymentId': vm.payment.paymentId }).value(); vm.revisionCount = getPaymentCount(); vm.showRevision = vm.revisionCount > 0; vm.isCurrentPayment = false; vm.showEffectiveDate = vm.payment.paymentType === 'ePayment'; $scope.$watch('vm.currentPaymentId', setIsCurrentPayment); function getPaymentCount() { return vm.details.length - 1; } function setIsCurrentPayment(currentPaymentId) { vm.isCurrentPayment = currentPaymentId === vm.payment.paymentId; } } })();

I have this directive that is not showing any values, even though when I break on the function, the vm variable has everything when each directive row is created.

(function () { angular .module('sales.directives') .directive("viewPayment", viewPayment); function viewPayment() { return { controller: 'ViewPaymentController', controllerAs: 'vm', bindToController: true, templateUrl: 'pages/viewPayment.html', restrict: 'E', scope: { payment: '=', paymentDetails: '=', setCurrentPayment: '&', currentPaymentId: '=', openLineItemDrawer: '&' } }; } angular .module('sales') .controller('ViewPaymentController', viewPaymentController); viewPaymentController.$inject = ['$scope']; function viewPaymentController($scope) { var vm = $scope; vm.details = _(vm.paymentDetails).where({ 'paymentId': vm.payment.paymentId }).value(); vm.revisionCount = getPaymentCount(); vm.showRevision = vm.revisionCount > 0; vm.isCurrentPayment = false; vm.showEffectiveDate = vm.payment.paymentType === 'ePayment'; $scope.$watch('vm.currentPaymentId', setIsCurrentPayment); function getPaymentCount() { return vm.details.length - 1; } function setIsCurrentPayment(currentPaymentId) { vm.isCurrentPayment = currentPaymentId === vm.payment.paymentId; } } })();

最满意答案

删除“controllerAs”并更改所有vm。 到范围。 解决了这个问题。

Removing the "controllerAs" and changing all of the vm. to $scope. fixed the issue.

更多推荐

本文发布于:2023-08-03 13:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390766.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指令   Angular   directive   values   displaying

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!