如何将对象传递给AngularJs中的指令控制器

时间:2016-01-05 01:43:00

标签: angularjs

我有一个名为dealEngine的指令,它有模板和控制器,工作正常。

但是你可以看到我正在尝试从属性中收集对象并将其传递给我的控制器!到目前为止,我得到undefined"string"

(function () {
    'use strict';
    angular
        .module('app')
        .directive('dealEngine', dealEngine)
        .controller("dealEngineCtrl", dealEngineCtrl);

    dealEngine.$inject = ['$state'];
    function dealEngine($state) {

        return {
            restrict: 'E',
            replace: 'true',
            cache:'false',
            controller: 'dealEngineCtrl',
            templateUrl: 'directives/deal/deal.html',
            scope:{
                "deal":"="
            }
        };

    }
    dealEngineCtrl.$inject = ['$scope','$attrs', '$element'];
    function dealEngineCtrl($scope, $attrs, $element) {
        console.log($attrs.deal); //this returns "vm.deal" string!!!
        console.log($scope.deal); //this returns undefined!!!
    }
})();

0 个答案:

没有答案