不更新我的組件的資料,因此,我的問題是這樣的:角 - 我的控制器在視圖
我的影片用了兩次一個組成部分,它定義了一個模板。
組件:
.component('topList', {
template: '<div class="well"> \
<div class="title"> \
<h3>{{$ctrl.model.title}}</h3><a href="#" class="close"><i class="ss-delete"></i></a> \
</div> \
<div ng-repeat="i in $ctrl.model.items" class="list-question"> \
<div class="item"><span class="number">{{$index + 1}}</span> \
<div class="description"> \
<h4>{{(i.Count/ $ctrl.model.total)*100 | number:2}}% ({{i.Count}} de {{ $ctrl.model.total }})</h4> \
<p>{{i.Description}}</p> \
</div> \
</div> \
</div> \
</div>',
controller: TopListController,
bindings: {
model: '='
}
})
function TopListController() {
}
控制器:
.controller('myController', function ($http, $scope, $controller, datesService) {
var ctrl = this;
$scope.api = function() {
var date = datesService.getDates();
$http.get("apicall/date.from/date.to").then(function (response) {
ctrl.model = {
title: 'Title',
items: response.data.Items,
total: response.data.Total
};
});
}
$http.get("apicall/date1/date2").then(function (response) {
ctrl.model = {
title: 'Title',
items: response.data.Items,
total: response.data.Total
};
});
})
HTML(玉實際上):
div(ng-controller="myController as controller")
top-list(model="controller.model")
當頁面被加載時,該組件被填充來自所述數據方法$ http.get被稱爲控制器被創建,但是當我從html調用方法api()時,dat一個不改變。
我從另一個控制器調用方法api()。
你混合'controllerAs'用' $ scope'控制器內部,所以你可能會感到困惑。你應該理想地放在控制器上下文中('this')。然後你可以調用方法,像'ng-click =「$ ctrl.api()」' –
我沒有明白,我忘記提到即時通訊從另一個控制器調用方法api。 – dpolicastro
你能解釋一下「從另一個控制器調用方法api」部分嗎?你的意思是api方法沒有從與控制器相對應的模板調用? –