범위를 변수로 사용하여 상태를 유지하고 상태간에 이동하려면 $timeout
을 연결합니다. 클릭 될 요소 그래서 :
<span ng-click="startChange()">Click me to start</span>
와 컨트롤러 :
$scope.state = 'a';
$scope.startChange = function() {
$scope.state = 'b';
return $timeout(angular.noop, 30 * 1000).then(function() {
$scope.state = 'c';
return $timeout(angular.noop, 60 * 1000);
}).then(function() {
$scope.state = 'd';
return $timeout(angular.noop, 120 * 1000);
}).then(function() {
$scope.state = 'e'
});
}
angular.noop
는 아무것도하지 않는 기능은이다. 다소 개인적인 취향이지만, $timeout
에 전달 된 콜백이 아무 것도하지 않고 범위의 모든 동작이 항상 약속의 성공 콜백 then
에있는 활동의 흐름을 보는 것이 더 쉽다는 것을 알았습니다. 배경 사업부의 템플릿에서
: 난 당신이 컨트롤러 나에있는 다른 무엇 확실하지 않다, 그러나
.background-state-a {background-color: red}
.background-state-b {background-color: green}
.background-state-c {background-color: blue}
...
:
<div class="background-state-{{state}}">....</div>
다음 CSS에서이 색상을 설정 정확한 유스 케이스. 비즈니스 로직을 뷰 로직과 섞을 수 있으므로 일부 로직을 지시문으로 분리해야 할 수 있습니다.
무엇이 당신을 뒤로 잡고 있습니까? – adrichman
어떻게 접근해야합니까? 한 번의 $ timeout을 120 초 생성하고 후속 $ timeouts를 root $ timeout에 중첩시켜야합니다. 나는 내가 직접 해결했을지도 모른다. : P – SinSync