我有一个名为customStyles的自定义指令,它的定义如下:
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中这是可能的吗?
发布于 2014-02-19 20:29:00
您应该在视图中重命名指令标记:
<custom-styles conversations="convList"> </custom-styles>以下是工作示例:
http://plnkr.co/edit/aOxf3fgS7Tc0sOyCXoBV?p=preview
https://stackoverflow.com/questions/21877437
复制相似问题