我有这样的标记
<i class="fa-font icon-user" wd-user-profile></i>
显示/隐藏这个 div
<div id="user-profile" ng-show="vm.isVisible">
<h3>user name</h3>
<h3>user email</h3>
<pre>{{vm | json:3}}</pre><!-- not updating on click -->
</div>
和这样的指令代码
angular
.module('myApp')
.directive('wdUserProfile', wdUserProfile);
function wdUserProfile() {
var ddo = {
restrict: 'A',
templateUrl: 'app/components/_shared/_userProfile.html',
controller: UserProfileController,
controllerAs: 'vm',
bindToController: true,
link: function(scope, elem, attr, ctrl) {
elem.bind('click', scope.vm.onIconClick);
//elem.bind('click', ctrl.onIconClick); also doesn't work
}
};
return ddo;
}
function UserProfileController() {
var vm = this;
vm.onIconClick = function() {
vm.isVisible = !vm.isVisible;
console.log(vm.isVisible);
};
}
问题是,虽然事件触发并且 vm.isVisible 变化很好,但在视图 div 中没有任何反应。有什么想法吗?