2017-11-21 13 views
0

私のアプリケーションにこのangularJS contextMenuモジュールを使用しています。これをいくつかのHTMLタグの中に動的に挿入する必要があります。私はこのようなことをしようとしていますが、うまくいきません。HTMLタグにangularJS contextMenuを動的に挿入してください

e.client.html("<a context-menu=\"menuOptions\">click here</a>"); 

私はこのような私のスコープにmenuOptionsを宣言している:

$scope.menuOptions = [ 
    { 
     text: 'Object-Select', 
     click: function ($itemScope, $event, modelValue, text, $li) { 
      $scope.selected = $itemScope.item.name; 
     } 
    }, 
    { 
     text: 'Object-Remove', 
     click: function ($itemScope, $event, modelValue, text, $li) { 
      $scope.items.splice($itemScope.$index, 1); 
     } 
    } 
]; 

誰かがそれを行う方法を知っていますか?

答えて

1

context-menuディレクティブを処理できるように、動的コンテキストメニューをコンパイルするには角度が必要です。これを行う最善の方法は次のとおりです。

//define the Html to insert in a variable: 
var dynContextMenu = "<a context-menu=\"menuOptions\">click here</a>"; 

//append to content 
e.client.html(dynContextMenu); 

//then compile it 
$compile(dynContextMenu)($scope); 

私はこれが役立つことを望みます。

+0

これは機能します。どうもありがとう! –

+0

あなたは歓迎です:) – scipper

関連する問題