【发布时间】:2014-07-30 17:41:03
【问题描述】:
我有一个视图,其中包含一个调用 PartialView 的链接。
<div data-ng-controller="MainController">
<a href="#" data-ng-click=callPartialView()">
Click here to see the details.
</a>
</div>
<script>
app.controller('MainController', ['$scope', 'HttpService',
function($scope, HttpService) {
$scope.callPartialView = function() {
HttpService.getModal('/Controller/ShowModalMethod', {});
};
}]);
</script>
我的 HttpService 服务有一个函数,它从控制器调用一个动作并返回一个 PartialView 以显示它。
getModal = function(url, params) {
$http.get(url, params).then(function(result) {
$('.modal').html(result);
});
}
PartialView 显示完美。当我尝试将控制器添加到该 PartialView 内容时,就会出现问题。
<div class="wrapper" data-ng-controller="PartialViewController">
<span data-ng-bind="description"></span>
</div>
<script>
alert('This alert is shown.');
app.controller('PartialViewController', ['$scope', 'HttpService',
function($scope, HttpService) {
$scope.description = "That's the content must have to appear in that bind above, but it isn't working properly.";
}]);
</script>
控制器无法按预期工作。我放在控制器内的没有出现在上面的那个 div 中。发生了什么?谢谢大家!
【问题讨论】:
标签: angularjs asp.net-mvc-partialview angularjs-controller