보기에서 컨트롤러를 호출하려고합니다. Chrome 개발자 도구를 사용했는데 컨트롤러가 호출 중이지만 실행 중이 아님을 압니다.컨트롤러 기능이 호출되었지만 실행되지 않습니다. AngularJS
제 목표는 서버를 호출하여 이후에 표시 할 채널에 대한 자세한 정보를 얻는 것입니다.
나는 그것이 실제로 작동하도록하기 위해 어디에서 보지 않습니까. 그런 종류의 코드를 디버깅하는 방법에 대한 조언이 있으십니까?
컨트롤러 :
angular.module('guideController').controller('scheduleController', ['$scope', 'API', function($scope, API) {
$scope.getChannelSchedule = function(channelId) {
API.getScheduleForChannelId(channelId)
.success(function(schedule) {
$scope.schedule = schedule;
})
.error(function(error) {
//ERROR management
});
};
}]);
공장 :
angular.module('guideService', [])
.factory('API', ['$http', function($http) {
return {
getScheduleForChannelId: function(channelId) {
return $http.get('http://localhost:5000/schedule/' + channelId);
}
};
}]);
하고 뷰 :
<div class="container" ng-controller="scheduleController">
test {{scheduleController.getChannelSchedule(1234)}}
</div>
편집 : 나는 내 문제를 해결 할 수있었습니다.
제가
<tr class="channel-body" ng-controller="channelController" ng-repeat="channel in channels | limitTo:40">
<td ng-repeat="program in programs">
{{program.title}}
</td>
</tr>
로 구문을 변경하고 컨트롤러를 개질 :
angular.module('guideController')
.controller('channelController', ['$scope', 'API', function($scope, API) {
$scope.getPrograms = function() {
alert($scope.schedule);
API.getScheduleForChannelId($scope.channel.channelId).
then(function(data) {
$scope.programs = data.data;
});
};
$scope.getPrograms();
}]);
그것을했다. 컨트롤러 사용법을 이해하지 못했습니다. 완벽하게 설계된 것은 아니지만 의도 한대로 작동하고 있습니다.
라고되고있는 방법이 될 수있다? 'scheduleController.getChannelSchedule()'이며 보간에서 함수를 실행하는 것은 의미가 없으며 (아무것도 반환하지 않음) scope 속성을 비동기 적으로 설정합니다. 신중하게 보간이 다이제스트주기마다 실행됩니다. – PSL
자바 스크립트에서 흔히 볼 수있는 것은, 함수의 결과가 아닌 함수 자체에 표현식을 할당하는 것입니다. '()'가 없습니다. – Claies
내 코드가 업데이트되었습니다. 디버깅하는 동안, 나는 펑키 한 것들을 시도하고 붙여 넣기를 복사하는 것은 잘못되었다. 하나의 매개 변수를 필요로하는 메서드를 호출하려고하는데, anglejs에 합법적입니까? – plog17