이유 코드를 작동하지 않에련 1.2?
-
20-12-2019 - |
문제
이 코드 작성을 가진 모난 접 1.2: http://jsfiddle.net/VmkQy/1/
<div ng-app="app">
Title is: <span my-directive data-title="Test title">{{ title }}</span>
</div>
angular.module('app', [])
.directive('myDirective', [function() {
return {
restrict: 'A',
scope: {title:'@'},
link: function($scope) {
alert($scope.title);
}
}
}])
;
범위 title
객실이지만,그것은 렌더링되지 않습니다.왜?
변경하는 경우 지시어 설정 scope:true
,그것은 잘 작동: http://jsfiddle.net/VmkQy/2/
angular.module('app', [])
.directive('myDirective', [function() {
return {
restrict: 'A',
scope: true,
link: function($scope, $element, attrs) {
$scope.title = attrs.title;
alert($scope.title);
}
}
}])
;
이는 버그 또는 기능을 각 1.2?이전 버전에서 작동합 이 모든 경우: http://jsfiddle.net/VmkQy/3/
해결책
이 {{title}}
안 <span />
면 교체합니다.추가 template: "{{title}}"
귀하의 지침 및 작동:
제휴하지 않습니다 StackOverflow