지시문이 있지만 지시문 제어기에서 속성을 보는 데 문제가 있습니다.지시선 컨트롤러에서 속성 변경 각도보기
angular.module('app',[])
.directive('timer1', function() {
return {
template: '<div class="timerCont1"><div class="progressBar"></div></div>',
restrict: 'E',
replace:true,
scope: true,
controller: function ($scope, $element, $attrs) {
$scope.$watch($attrs.timerevent, function (value) {
switch ($attrs.timerevent)
{
case "start":
$scope.timeoutId = null;
$scope.countdown = Number($attrs.timer);
$scope.tick();
break;
case "stop":
$scope.stop();
break;
case "destroy":
alert()
$scope.stop();
$scope.$emit('destroy_pizza', {
});
}
},true);
$scope.tick = function() {
$scope.timeoutId = setTimeout(function() {
if ($scope.countdown <= 0) {
$scope.$apply(function() {
$attrs.$set('timerevent', 'destroy')
});
}
else {
$scope.countdown--;
$scope.tick();
}
$scope.$apply();
}, $attrs.interval);
};
$scope.stop = function() {
clearTimeout($scope.timeoutId);
$scope.timeoutId = null;
};
}
};
});
그리고 여기 내 HTML 나는 속성이 성공적으로 업데이트되는 반면, 내 시계가 호출 받고 있지 않습니다 "파괴"하는 속성 TimerEvent를 설정하고
<timer1 interval="1000" timerevent="start" timer="10"></timer1>
간다.
범위 변수 대신 타이머 구성 요소를 제어하기 위해 특성을 사용하는 이유는 무엇입니까? 당신의 문제를 해결하기위한 답을 쓸 수는 있지만,이 구성 요소의 설계에 대한 전체적인 접근은 현명하지 못한 것처럼 보입니다. 자세한 내용은 [AngularJS 개발자 가이드 - 구성 요소 기반 응용 프로그램 아키텍처] (https://docs.angularjs.org/guide/component#component-based-application-architecture)를 참조하십시오. – georgeawg
또한'replace = true'는 더 이상 사용되지 않습니다. 자세한 내용은 [AngularJS에서 대체되는 이유는 무엇입니까?] (https://stackoverflow.com/questions/24194972/why-is-replace-deprecated-in-angularjs/35545445#35545445)를 참조하십시오. – georgeawg
@georgeawg jquery 플러그인을 포함하는 것을 잊어 버린 것 같습니다. 다음은 작동중인 플 런커입니다. https://plnkr.co/edit/ZYLsDNmH4sYMn2N45dot –