내 문제는 다음과 같습니다.각도 - 내 컨트롤러가 뷰의 구성 요소 데이터를 업데이트하지 않습니다.
두 번 사용되는 구성 요소가 있고 템플릿이 정의되어 있습니다.
요소 :
.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 메소드가 컨트롤러에 해당하는 템플릿에서 호출되지 않았습니까? –