である私は私の角のアプリケーションでツールチップを作るために、次のディレクティブのコードを使用しています:
//Creates a directive that is used to display tooltips throughout the application
app.directive('tooltip', function(){
return {
restrict: 'A',
link: function(scope, element, attrs){
$(element).hover(function(){
// on mouseenter
$(element).tooltip('show');
}, function(){
// on mouseleave
$(element).tooltip('hide');
});
}
};
});
トラブルは、私が
を受けるということです$は定義されていません
コンソールにあります。今、私の取り組みは、これらがjQueryのメソッドであるということです。私はこのアプリ(これのみツールチップのために使用される場合は特に)にはjQueryを使用して回避しようとしているので、次のように、私はコードを変更することを決定した:第2のケースで
//Creates a directive that is used to display tooltips throughout the application
app.directive('tooltip', function(){
return {
restrict: 'A',
link: function(scope, element, attrs){
document.getElementById(element).hover(function(){
// on mouseenter
document.getElementById(element).tooltip('show');
}, function(){
// on mouseleave
document.getElementById(element).tooltip('hide');
});
}
};
});
を、エラーがI状態を受け取ります
私はエラーをクリアし、jQueryの使用を避けることができる方法
ヌル
のプロパティホバーを読み取ることができません。これは可能ですか?編集:エラーをクリアするには、次のように私は、コードを変更した
:
//Creates a directive that is used to display tooltips throughout the application
app.directive('tooltip', function(){
return {
restrict: 'A',
link: function(scope, element, attrs){
element.on('mouseenter', function() {
element.tooltip('show');
});
element.on('mouseleave', function() {
element.tooltip('hide');
});
}
};
});
しかし、今element.tooltip is not a function
。ここで勝つことは可能ですか? :)
FYIでは、DOM要素には '.hover()'メソッドがありません。これはjQueryメソッドです。 – jfriend00
「要素」の説明については、以下の回答を参照してください。これはjqLiteオブジェクトです。 – MadPhysicist