标记看起来像:
<div id="communication-list" ng-controller="contactListController">
<li ng-repeat="contact in contacts" ng-controller="contactItemController" ng-dblclick="chatWithUser(contact)" ng-click="contactItemClick($event)">
<div class="name">{{ contact.username }}</div>
<ul ng-hide="popoverHide">
<button ng-click="chatWithUser(contact)">Send Message</button>
</ul>
</li>
</div>
contactItemController 看起来像:
FF.controller('contactListController', ['$scope', '$rootScope', function($scope, $rootScope) {
// Start Text chat
$scope.chatWithUser = function(currentContact) {
AppManager.startConversation(currentContact.id);
}
}
FF.controller('contactItemController', ['$scope', '$element', function($scope, $itemElement) {
$scope.popoverHide = true;
$scope.contactItemClick = function(event) {
console.log('test'); // prints.
$scope.popoverHide = !$scope.popoverHide;
event.stopPropagation();
};
}]);
是否存在范围问题?不确定发生了什么。我还尝试将 $scope.popoverHide 设置为 false 只是测试但没有成功。
最佳答案
将其放置在 Controller 内,其范围为:
FF.controller( 'contactListController', ['$scope', '$rootScope', $element, function( $scope, $rootScope, $itemElement )
{
$scope.chatWithUser = function( currentContact )
{
AppManager.startConversation( currentContact.id );
}
$scope.popoverHide = true;
$scope.contactItemClick = function( event )
{
console.log('test'); // prints.
$scope.popoverHide = !$scope.popoverHide;
event.stopPropagation();
};
}
关于javascript - AngularJS ng-hide 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26989111/