即使$ scope变量为true,ng-show也不起作用

时间:2017-08-14 04:35:42

标签: javascript angularjs

为什么我的div仍然具有ng-hide,即使ng-show是真的,至少范围显示它是真的。我不确定这里发生了什么

html文件

        <div class="agent-content-wrapper" ng-controller="LoaCtrl">
            <div class="list-of-agent">
                <div class="loa-header">List of Agents</div>
                <div class="agent-list" ng-repeat="agent in ListOfAgents">
                    <div class="agent-main-list">
                        <div class="agent" ng-click="goToAgentRecords(agent)">{{agent.name}}</div>
                    </div>
                </div>
                <div class="agent-details" ng-show="IsAgentSelected" ></div>
            </div>
        </div>

js file

$scope.IsAgentSelected = false;
$scope.goToAgentRecords = function (agent) {
    $scope.IsAgentSelected = true;
}

2 个答案:

答案 0 :(得分:0)

对我来说它工作正常, 请在ng-show div中写一些内容以查看它的效果。

我的代码如下:

的index.html

<div class="agent-content-wrapper" ng-controller="LoaCtrl">
            <div class="list-of-agent">
                <div class="loa-header">List of Agents</div>
                <div class="agent-list" ng-repeat="agent in ListOfAgents">
                    <div class="agent-main-list">
                        <div class="agent" ng-click="goToAgentRecords(agent)">{{agent}}</div>
                    </div>
                </div>
                {{IsAgentSelected}}
                <div class="agent-details" ng-show="IsAgentSelected" >Display Ng- Show</div>
            </div>
        </div>

Controller.js

var myApp = angular.module('myApp', []);
myApp.controller('LoaCtrl',['$scope',function($scope){
$scope.ListOfAgents =['a','b','c']
$scope.IsAgentSelected = false;
$scope.goToAgentRecords = function (agent) {
    $scope.IsAgentSelected = true;
}
}]);

我在div中打印了IsAgentSelected的值以查看其正确的值,您可以在它正常工作后将其删除。 如果仍然没有合作评论。

答案 1 :(得分:0)

谢谢你们。一段时间后它正在运作。我不明白为什么它不能早点工作。