访问 angularjs 中的数据属性
Accessing data attribute in angularjs
我正在尝试访问我的 angular 控制器中的 html 数据属性,但即使该属性实际上是在 html 中动态设置的,也会不断返回 'null':这是代码:
<button class="btn" ng-data-stuff="{{psn._id}}" ng-click="person.doStuff($event.target)">
Follow
</button>
self.doStuff = function (e) {
$window.alert(e.attributes('data-stuff'))
}
按钮中没有名为 ng-data-stuff 的属性,您可以直接将 psn 值传递给按钮函数,如下所示,
<button class="btn" ng-click="person.doStuff(psn)">Follow </button>
在函数内部,
self.doStuff = function (e) {
$window.alert(e._id);
)
我正在尝试访问我的 angular 控制器中的 html 数据属性,但即使该属性实际上是在 html 中动态设置的,也会不断返回 'null':这是代码:
<button class="btn" ng-data-stuff="{{psn._id}}" ng-click="person.doStuff($event.target)">
Follow
</button>
self.doStuff = function (e) {
$window.alert(e.attributes('data-stuff'))
}
按钮中没有名为 ng-data-stuff 的属性,您可以直接将 psn 值传递给按钮函数,如下所示,
<button class="btn" ng-click="person.doStuff(psn)">Follow </button>
在函数内部,
self.doStuff = function (e) {
$window.alert(e._id);
)