我有一个$ scope.selected(一个返回选中值的模态)要在ModalInstanceCtrl控制器中创建并在displayValue控制器中使用,如何在第二个控件中使用第一个控制器值,
app
.controller('DemoCtrl', function ($scope, $modal) {
console.log("in angular");
$scope.selected = null;
$scope.open = function() {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
size: 'lg'
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
});
};
})
.controller('ModalInstanceCtrl', function ($scope, $modalInstance) {
$scope.setSelectedSegment = function (value) {
$scope.selected = value;
$modalInstance.close($scope.selected);
};
})
.controller('displaySelected', function ($scope) {
// get selected from ModalInstanceCtrl controller
$scope.displayValue= $scope.selected;
};
})
答案 0 :(得分:1)
您需要为此目的创建angularjs服务,然后将服务包含在您需要访问其值的位置。
[self bannerView:self.adBanner didFailToReceiveAdWithError:nil];