gpt4 book ai didi

javascript - AngularJS ng-hide 不工作

转载 作者:行者123 更新时间:2023-11-28 19:30:09 24 4
gpt4 key购买 nike

标记看起来像:

<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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com