Angular指令不显示任何值

时间:2015-03-11 15:54:35

标签: angularjs angularjs-directive angularjs-scope

我有这个没有显示任何值的指令,即使在我打破函数时,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;
        }
    }
})();

1 个答案:

答案 0 :(得分:0)

删除" controllerAs"并改变所有的vm。到范围。解决了这个问题。