I created a directive for showing tooltips:
app.directive('tooltip',function(){
return{
restrict: 'A',
link: function(scope,element,attr){
element.bind('mouseenter',function(e){
scope.setStyle(e);
});
}
}
});
The corresponding setStyle()
function:
$scope.setStyle = function(e){
$scope.style = {
position: 'absolute',
// some other styles
};
$scope.$digest();
};
$scope.style
is applied to this:
<span ng-style="style">I am a tooltip</span>
which is part of my view, handled by the controller who owns $scope.style
Why do i have to call $digest()
in order to apply the changes to $scope.style
, which was declared and initialized earlier?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…