0
我想在我的指令中訪問標題的完整值。 指令中的標題應該顯示爲「Hi from Sample」。 現在它是「你好」。 有人也可以解釋爲什麼會發生?如何在angular 1.5中訪問指令中的屬性文字值?
角代碼
angular.module('docsTransclusionExample', [])
.controller('Controller', ['$scope', function($scope) {
$scope.title = 'Sample';
}])
.directive('myDialog', function() {
return {
restrict: 'E',
replace: true,
transclude: true,
scope: {},
template: '<div>'+attr.title'</div>',
link: function(scope,title) {
scope.title = attr.title;
}
};
});
HTML
<my-dialog title="Hi from {{title}}"><h2>Hello</h2>
</my-dialog>