ツールチップを表示するためのディレクティブを作成しました:
app.directive('tooltip',function(){
return{
restrict: 'A',
link: function(scope,element,attr){
element.bind('mouseenter',function(e){
scope.setStyle(e);
});
}
}
});
対応するsetStyle()
機能:
$scope.setStyle = function(e){
$scope.style = {
position: 'absolute',
// some other styles
};
$scope.$digest();
};
$scope.style
これに適用されます:
<span ng-style="style">I am a tooltip</span>
これは私のビューの一部であり、所有するコントローラーによって処理されます$scope.style
以前に宣言および初期化され$digest()
た に変更を適用するために、なぜ を呼び出さなければならないのですか?$scope.style