[英]AngularJS ng-show doesn't work
我有以下代碼:
<header class="hero-unit" id="banner" ng-include="'components/header/header.html'"></header>
<div ng-include="'components/navbar/navbar.html'"></div>
<div class="container">
<h3 class="site-headline">Opret nyt produkt</h3> <hr>
<form>
<div class="container jumbotron">
<div class="col-md-12">
<select ng-model="selectedOption">
<option ng-repeat="option in options">
{{ option.name }}
</option>
</select>
</div>
<div ng-show="selectedOption.name == Pool" ng-include="'components/new/new-pool.html'">test</div>
</div>
</form>
</div>
<footer class="footer" ng-include="'components/footer/footer.html'"></footer>
而且我試圖每當selectedOption == "Pool"
時顯示ng-include,但是即使ng-show條件不正確,也會顯示ng-include。
我已經嘗試過使用" ==='Pool'"
且不使用'
,但是似乎沒有任何效果,而且我無法將其包圍。
您正在比較selectedOption.name == Pool
,它碰巧是undefined == undefined
。 由於您是如何設置ng-select
,因此只想比較一下:
selectedOption === 'Pool'
看到這個簡單的朋克 。
無論是讓你為模型select
是selectedOption.name
或您的條件被ng-show="selectedOption == 'Pool'"
你的條件正在尋找一個不同的變量比你的設置select
( selectedOption
與selectedOption.name
)。 (另請注意“ Pool”周圍的引號)
我不確定,但是您可能需要給您的option
元素一個值。
我設法找到我的問題
不知何故,我設法創造了一個空間,所以它沒有說
Pool
但它說
Pool
從此更改:
<option ng-repeat="option in options">
{{ option.name }}
</option>
對此:
<option ng-repeat="option in options">{{ option.name }}</option>
解決了我的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.