0
我有一个名为customStyles一个自定义的指令,它的定义是:动态更新模板的HTML在角度指令
scrollbackApp.directive('customStyles', function(){
return{
restrict: 'E',
template: '<style> {{styleString}} </style>',
scope: {
conversations : '='
},
link: function($scope, elem, attrs){
$scope.$watch('conversations', function(value){
// calculate str based on value
$scope.styleString = str;
});
}
}
});
我加入这个指令到我的HTML视图的身体:
<body>
<custom-styles conversations="convList"> </custom-styles>
</body>
并且convList
的值在父控制器范围内发生变化。目前,当上述指令呈现给Html时,{{styleString}}
绑定仍然是一个字符串,而不是变成它的值。我希望指令的html根据styleString
的值动态更改。这在Angular中可能吗?
你能做到styleString的例子吗? btw函数(值)应该是函数(str) – Whisher