2017-03-12 58 views
0

我有一个html页面,其中包括如下。AngularJS包含刷新

<ng-include src="lowerTabURL"></ng-include> 

此页面包含一个devextreme控件,该控件通过ajax加载数据源。

HTML:

<div class="tab-container" style="height:100%; width:100%"> 
    <div dx-tabs="lowerTabOptions" dx-item-alias="lowerTab"> 
    </div> 
</div> 

控制器:

DemoApp.controller('NavigationController', function DemoController($scope, $templateCache) { 
$scope.lowerTabURL = "LowerPanelTest"; 

$scope.currentSidebarId = 10100; 

$scope.lowerTabOptions = { 
    dataSource: new DevExpress.data.CustomStore({ 
     load: function (loadTabOptions) { 
      console.log('get tabs'); 

      var d = $.Deferred(); 
      $.ajax({ 
       url: 'GetLowerTabs', 
       data: { currentSidebarId: $scope.currentSidebarId }, 
       type: 'GET', 
       success: function (result) { console.log(result); d.resolve(result); } 
      }); 

      return d.promise(); 
     } 
    }), 
    animationEnabled: true, 
    swipeEnabled: true, 
    itemTitleTemplate: 'title', 
    height: '100%' 
}; 


$scope.navBarClicked = function (sidebarId) { 
    console.log(sidebarId); 
    $scope.currentSidebarId = sidebarId; 
} 
}); 

这正常工作,但是我必须点击它时,应该更改标签控件的导航栏。

目前我正在改变传递给ajax调用的sidebarId,但我需要一种方法来重新加载包含页面,以便再次调用它。我试图更改lowerTabUrl,然后再次更改它,但这不刷新页面。做这个的最好方式是什么?

回答

0

这取决于你的角度版本,则需要对PARAM sidebarId值发生变化后观看,@角1,这是通过scope.watch

scope.$watch('sidebarId', function(newValue, oldValue) { 
    // ..call refresh here 
}); 

在角达到1.5及更高版本,您可以覆盖ngOnChages

this.$onChanges = function (changesObj) { 
    if (changesObj.sidebarId) { 
     // changesObj.sidebarId.currentValue 
    } 
    };