对 Angular JS 不是很熟悉,但这是我所拥有的和我想要的:
<div ng-app="MyApp" ng-controller="appController">
<div class="input-group">
<input class="form-control enableEnter" type="text" ng-model="action"/>
<div class="input-group-btn">
<button class="btn btn-primary" ng-click="search()">Search</button>
</div>
</div>
<ul class="dropdown-menu" id="list" ng-show = {{display}} >
<li> hello </li>
<li class="dropdown" ng-repeat="x in actions">
{{x.name}}
</li>
</ul>
</div>
我的js文件:
MyApp.controller('appController', ['$scope', function ($scope) {
$scope.actions = [];
$scope.display=false;
$scope.search = function () {
$.get("http://localhost:8080/get/something/" + $scope.action)
.success(function (response) {
console.log(response);
$scope.actions = response['RESPONSE'];
$scope.display=true;
}).error(function (jqXHR, textStatus, errorThrown) {
console.error("Error retrieving something list", textStatus, errorThrown);
});
}
}]);
$scope.actions
在 Controller 中初始化为空,但是在单击“提交”按钮时,我们得到一个填充在 actions
中的操作列表。 .我想在表格下方显示此列表。为此,我正在更改 ng-show
的值单击提交时。这是否应该自动更新 <UL>
元素?因为我点了之后好像什么也看不到。
最佳答案
您不需要在 ng-show
中插入 {{ }}
:
<ul class="dropdown-menu" id="list" ng-show="display" >
<li> hello </li>
<li class="dropdown" ng-repeat="x in actions">
{{x.name}}
</li>
</ul>
您可能还想查看 ng-if
关于javascript - 使 DOM 元素可见并刷新 : Angular JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30299217/