在homeController文件里面我有功能
$scope.MyFunction = function () {
$http({
method: 'POST',
url: '/SomeUrl/ActionToDo',
data: { id: 1001 },
}).success(function (response) {
if (response.Status == 1) {
//success to do
}
$modal.open({
controller: 'modalController',
templateUrl: '/app/views/modalTemplate.html',
resolve: {
myData: function () {
return response;
}
}
});
} else {
alert(error);
}
}).error(function () {
alert('Error!');
});
}
我在哪里调用modalController打开模式窗口。问题是如何将数据从homeController传递到此 Controller (modalController),以便注入(inject)当前选择的语言,该语言在homeController内部可用,类型为
$scope.selLanguage
最佳答案
您可以将其作为解析依赖项注入(inject)到 Controller 中:
$modal.open({
controller: 'modalController',
templateUrl: '/app/views/modalTemplate.html',
resolve: {
myData: function () {
return response;
},
language: $scope.selLanguage
}
});
因此它将在 Controller 中作为服务提供
.controller('modalController', function(myData, language) {
console.log(language);
})