2016-05-03 3 views
1

を使用して取得されたコンテンツをhtmlのことができ、.htmlを()メソッドが動作します。がどのようにjqueryの中angularjs

私はNGリピート内部私の角度のアプリで同じことをしようとすると、私は何も得ます。

アドバイス?

$(".recentChats").click(function(){ 
    var value = $(this).html(); 
    $scope.htmlContent = value; 
}); 

答えて

0

あなたはAngularJS $eventを使用することができます。

Working Demo

HTML:

<div ng-click="clickMe($event)"> 
    This is test content. 
</div> 

はJavaScript:

$scope.clickMe = function($event){ 
    console.log($event.currentTarget); 
    console.log($event.currentTarget.innerText); 
} 
0

あなたはDOMから何かを得るか、変更するjQueryのを使用したいいつでも、あなたはディレクティブのlink機能を使用する必要があります。

.directive('clickDirective', function() { 
     return function (scope, elem) { 
      elem.on('click', function() { 
       var value = elem.html(); 
       scope.htmlContent = value; 
      }); 
     }; 
    }); 

HTMLは

<div ng-repeat="thing in things" click-directive>Do Something {{ thing.name }}</div> 
関連する問題