我在我看來,有這樣的:AngularJs div一定不會切換使用<select>
<div>
<select ng-model="chartType" ng-change="AnalyticsChartTypeChanged(chartType)"
ng-init="chartType='Data grid'">
<option value="Data grid">Data grid</option>
<option value="Histogram">Histogram</option>
</select>
{{chartType}}
<br>showAnalyticsDataGrid == {{showAnalyticsDataGrid}}
<br>showAnalyticsHistogram == {{showAnalyticsHistogram}}
<div ng-show="{{showAnalyticsDataGrid}}">
<p>Data grid goes here</p>
</div>
<div ng-show="{{showAnalyticsHistogram}}">
<p>Histogram goes here</p>
</div>
和NG-chnage funtion是
$scope.AnalyticsChartTypeChanged = function(chartType)
{
switch (chartType)
{
case 'Data grid': $scope.showAnalyticsDataGrid = true;
$scope.showAnalyticsHistogram = false;
console.log('Show analytics data grid');
break;
case 'Histogram': $scope.showAnalyticsDataGrid = false;
$scope.showAnalyticsHistogram = true;
console.log('Show analytics histogram');
break;
}
}
當我alernately選擇每個選項,調試文字更新correcrly:
Data grid
showAnalyticsDataGrid == true
showAnalyticsHistogram == false
和
Histogram
showAnalyticsDataGrid == false
showAnalyticsHistogram == true
但是,它不斷顯示數據網格DIV和從不Historgram DIV。
Obviouly我想提出一個簡單的extermely的錯誤,但我看不出它:-(