1
我有类似这样的标记角指令controlleras和纽带
<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没有任何反应。有什么想法吗?
它不工作,所有的控制台是红色的(错误:$ rootScope:inprog 行动已在进行中) –
@ georgiy.zhuravlev它应该工作..虽然尝试更新.. –
适用()导致错误,但$超时版本的作品很棒,谢谢! –