캘린더 앱이 있습니다. 초기화 후에 모든 것이 올바르게 작동합니다. 문제는 내가 모델 (월)을 변경 한 후 지시문이 새로 작성된 요소를 업데이트하지 않는 것입니다.AngularJS - 모델 업데이트 후 지침을 트리거하지 않음
뷰 부분 :
<li class="day" ng-repeat="n in [] | range:month.daysInMonth()">
<span class="day-number" calendar-day="{{ n }}-{{ month.format('MM-YYYY') }}">{{ n }}</span>
</li>
이 지침 : 여기
value('month', moment());
코드는 다음과 같습니다 :로
directive('calendarDay', ['month', function (month) {
return function (scope, element, attrs) {
scope.$watch(month, function (value) {
var currentDate = moment(attrs.calendarDay, "DD-MM-YYYY");
element.text(currentDate.format('DD-MM-YYYY'));
});
};
}]);
이 모델 month
앱에서 선언 된 모델이다 http://jsfiddle.net/EEVGG/11/
여러분이 보시다시피, 코드의 월 및 연도 부분은 변경되지 않지만, calendar-day
속성의 값이 정확해야하기 때문에 코드의 월 및 연도 부분이 변경되지 않습니다.