我想用茉莉花测试角度'ng-click'事件,但我不知道怎么做
我的指令文件是这样的(headbarDirective.js):
(function () {
angular.module('app.widgets.homeHeadbar',[])
.directive('homeHeadbar', homeHeadbar);
function homeHeadbar() {
return {
restrict: 'EAC',
replace: true,
transclude: false,
scope: {
name: '@',
role: '@',
},
templateUrl: 'app/widgets/headbar/headbarView.html',
link: function(scope, ele, attrs) {
if (!scope.name) {
scope.logined = false;
} else {
scope.logined = true;
}
scope.logout = function() {
UserService.logout();
$location.path('/login');
};
}
};
}
})();
Run Code Online (Sandbox Code Playgroud)
像我这样的模板文件(headbarView.html):
<nav>
<div>
<div class="navbar-right" ng-show="logined">
<div class="dib fr ml20">
<div class="user-name cwh">{{name}}</div>
<div class="user-position cgray">{{role}}</div>
</div>
<a class="logout" href="javascript:;" ng-click="logout()">Log Out</a>
</div> …Run Code Online (Sandbox Code Playgroud)