2017-02-28 14 views
0

<span></span>の属性を取得する必要があります。私はこれに問題があります。私はこれを達成する方法を知りません。 私は属性「validacion」(「VALUE1値2の値3」)Angular.jsでスパンの属性を取得

<span data-id="345" ng-click="getAtributte($event.target)" validacion="value1 value2 value3">Button</span> 

$scope.getAtributte = function (item) { 
    console.log(angular.element(item)); 
}; 

答えて

0

次の2つの方法でそれを使用することができます。

  • angular.element(アイテム)[0] .attributes.validacion.nodeValue
  • angular.element(アイテム).ATTR( 'validacionを「)

DEMO

var myApp = angular.module('myApp',[]); 

myApp.controller('MyCtrl',function($scope) { 
    $scope.getAtributte = function (item) { 
    console.log(angular.element(item)[0].attributes.validacion.nodeValue); 
    console.log(angular.element(item).attr('validacion')); 
}; 
}); 

<div ng-app="myApp" ng-controller="MyCtrl"> 
<span data-id="345" ng-click="getAtributte($event.target)" validacion="value1 value2 value3">Button</span> 
</div> 
0
$scope.getAtributte = function (item) { 
    console.log(angular.element(item).attr('validacion')); 
}; 

を取得したいあなたはこれをやろうとしているという事実は、これまでより良い(より多くの角度)のアプローチは、おそらくそこにあることを示唆しています。

関連する問題