我有一个案例需要确认删除Angular中的数据,我是这样做的(以及Angular UI Bootstrap):
$scope.delete = (id) ->
$scope.setId = id //here the $scope.setId is 543
$modal.open
templateUrl: 'deleteModalContent.html'
controller: modalInstanceController
modalInstanceController = ['$scope', '$modalInstance', ($scope, $modalInstance) ->
$scope.delete_ok = ->
console.log $scope.setId //here the value becomes undefined
$scope.delete_cancel = ->
$modalInstance.dismiss 'cancel'
]
正如我在代码中说明我的问题(在评论上),id在不同的控制器中未定义,没有$rootscope
,我该如何解决这个问题?
答案 0 :(得分:2)
查看此帖子What's the correct way to communicate between controllers in AngularJS?
您必须使用根范围来共享值或服务。