我的指令包含一個JavaScript對象。我試圖找到與jquery綁定到這個javascript對象的所有html元素。如何使用jquery獲取angularjs對象的綁定數據?從帶有angularjs指令的html元素中提取綁定的angularjs數據
也許上面的代碼更好地解釋了我的計劃。
angular.module('app').directive('highlight', [
'$rootScope', '$compile', function ($rootScope, $compile) {
return {
replace: true,
templateUrl: 'highlight.html',
link: function (scope, element, attrs) {
//this data object do we need to highlight
scope.Tohighlight;
$($.find('input, select')).each(function() {
//todo extract data if input or selection are binding data
//<input type="x" data-ng-model="data" /></span>
var data = angular.extractDataFromhtmlelement($(this));
//if html element contains our data add some css stuff
if(data == scope.Tohighlight)
{
}
});
};
}
]);
我不知道我的目的是否存在angularjs方法。我怎樣才能得到綁定的jQuery對象的angularjs數據模型?謝謝。
我已經更新了我的答案http://stackoverflow.com/a/26578630/947687。對你有幫助嗎? – dizel3d 2014-10-27 08:54:01