AngularJS:$ modal,将$ scope变量传递给子控制器

时间:2015-08-14 08:04:02

标签: angularjs angularjs-scope

JS Code,

var mod= $modal.open({
    animation: true, 
    templateUrl: $scope.url,
    controller: function($scope, $modalInstance,custObj) {
        alert(custObj); /*************Line 1**************************/
        $scope.save = function() {
            $modalInstance.close();
        };

        $scope.cancel = function(){
            $modalInstance.dismiss('cancel');
        };

    },
    resolve : {
        /************Resolving current scope value to retrieve it in Line 1*******/
        custObj: $scope.customer;
    }
}); 

虽然我通过$scope.customer属性发送了resolve对象,但模态控制器没有获取值。我错过了什么吗?

2 个答案:

答案 0 :(得分:1)

custObj - 对象中resolve的值应该是一个返回你要注入的函数的函数:

resolve: {
  custObj: function(){
        return $scope.customer;
     }
}

检查documentation $ routeProvider resolve

答案 1 :(得分:0)

使用

locals : {
   custObj: $scope.customer;
}

而不是解决。