0
서비스 변수가 변경 될 때마다 함수를 호출해야하는 지시문이 있습니다.
다음 코드는 지시어 내부 :
$rootScope.$watch('movesService.selectedMove', function() {
console.log(movesService.selectedMove);
if (movesService.selectedMove === "Punch") {
vm.pushToFightLog('Select Target');
}
if (movesService.selectedMove === "Fury") {
//Action
}
if (movesService.selectedMove === "Fortify") {
//Action
}
if (movesService.selectedMove === "Parry") {
//Action
}
}, true);
서비스 :
angular
.module('outerZone')
.service('movesService', movesService);
function movesService() {
var vm = this;
vm.selectedMove = "Punch";
}
건은 $ 시계가 처음 호출 될 때 변수와 로그를 읽을 수 있다는 것이다 그것은 콘솔에 있지만 변수가 변경된 후에도 함수를 실행하지는 않습니다.
나는 $ rootScope가 제대로 주입되었다고 확신하지만 여기서는 다시 확인하기위한 코드 만있다.
angular
.module('outerZone')
.directive('fightDisplay', fightDisplay);
fightDisplay.$inject = ["alliesService", "enemiesService", "fightQueueService", "$timeout", "movesService", "$rootScope"];
function fightDisplay(alliesService, enemiesService, fightQueueService, $timeout, movesService, $rootScope) {
우리가 작업을 할 수 있습니다 확인 작업 멍청이? 그것은 우리가 빨리 대답하는 데 도움이 될 것입니다! –
본질적으로 이것이 작동하지 않는 이유가 궁금합니다. https://plnkr.co/edit/YBrHJkblkZBmo4ozGusr?p=preview –
답변이 도움이 되었습니까? –