2017-07-01 22 views
0

在我的應用我使用autoscroll="true"我可以autscroll = false爲在角路由器的UI一些特定狀態

<ui-view autoscroll="true"> 
</ui-view> 

而這對於期望在大多數情況下的行爲。

但是我可以設置autoscroll=false針對某些特定國家(比如,例如,當內容被添加到頁面的底部)?

+0

我知道文檔聲明我可以在'autoscroll'屬性中使用一個表達式,但是有沒有任何示例說明如何將切換自動滾動變量的狀態結合起來? –

回答

0

化妝服務命名爲scrollService

app.service('scrollService',function(){ 
    var self = this; 
    self.scrollEnabled = false; //default scroll Status 
    self.enable = function(){ 
     self.scrollEnabled = true; 
    } 
    self.disable = function(){ 
     self.scrollEnabled = false; 
    } 

}); 

//該控制器將是UI的視​​圖元素

app.contoller('bodyCtrl',function(scrollService){ 
    var ctrl = this; 
ctrl.scrollService = scrollService; 

}) 

//假設該控制器將當前狀態控制器

父控制器
app.controller('usersCtrl',function(scrollService){ 
// if i need this state to be auto scroll 
scrollService.enabled(); 
// if i need to prevent auto-scroll 
scrollService.disable(); 
}) 

// for the HTML must like like

<body ng-controller="bodyCtrl as ctrl"> 
<ui-view autoscroll="ctrl.scrollService.scrollEnabled" ></ui-view> 
</body> 
+0

謝謝!我有這個想法,它的工作原理。 –