访问控制器功能
问题描述:
HTML作为内容内的元件内html和属性值,访问控制器功能
<div ng-controller="logCtrl">
<ul>
<li ng-click="logMe" someAttr="hello ricky">hello martin</li>
</ul>
</div>
的Javascript内容,
var app = angular.module('app', []);
app.controller('logCtrl', function ($scope, $element) {
$scope.logMe = function(){
console.log("html content is " + /*---- how can i print $element's inner html text here --- */)
console.log("attribute value is " + /*---- how can i read the li element's someAttr value here --- */)
}
})
这必须在控制台打印这个消息(当用户点击鼠标),
html content is hello martin
attribute value is hello ricky
答
尝试这样
HTML
<li ng-click="logMe($event)" someAttr="hello ricky">hello martin</li>
控制器
$scope.logMe = function(e){
var value=e.target.attributes.someAttr.value;
}
你可以使用jQuery做..