2014-12-03 131 views
2

我正在使用ui.bootstrap,我試圖使用collapse函數。如何將ui.bootstrap摺疊功能設置爲在頁面加載時摺疊?

在我的代碼中,發生的情況是默認狀態是展開的,當點擊load weather按鈕時,div已摺疊,數據加載完成後展開。

我需要對我的代碼做些什麼才能讓它在頁面加載時處於摺疊狀態,並且只有在按鈕被點擊後才展開/收縮?

這裏是我的代碼:

<div ng-controller="weatherCtrl"> 
    <div> 
     <button ng-model="hotel" class="btn btn-default" 
      ng-click="loadWeather(hotel); isCollapsed = !isCollapsed">load weather</button> 
     <hr> 
     <div collapse="isCollapsed"> 
      <div class="well well-lg">Some content</div> 
     </div> 
    </div> 
</div> 

.controller('weatherCtrl', function ($scope, weather) { 

    $scope.loadWeather = function (hotel) { 
     console.log('loadWeather') 
     console.log('hotel') 
     console.log(hotel) 

     weather.get({}, function (data) { 
      console.log('data') 
      console.log(data) 
      $scope.isCollapsed = false; 
     }) 
    } 
}) 

回答

0

我得到了它的父元素使用ng-init工作:

<div ng-controller="weatherCtrl" ng-init="isCollapsed = !isCollapsed"> 
    <div> 
     <button ng-model="hotel" class="btn btn-default" 
      ng-click="loadWeather(hotel)">load weather</button> 

     <hr> 

     <div collapse="isCollapsed"> 
      <div class="well well-lg">Some content</div> 
     </div> 
    </div> 
</div> 
+0

如何點擊功能在這裏保留?你也必須改變你的控制器。 – isherwood 2015-02-09 18:27:05

+0

當我有分鐘時,我會查看我的代碼,然後看看我做了哪些其他更改。 – user1532669 2015-02-18 09:47:28

+0

我不知道我做了什麼修改,但您可以在這裏查看:http://hoteldemo.t15.org/responsive/html/ – user1532669 2015-04-28 11:43:10