AngularJS部分重新加载

时间:2012-10-20 16:26:50

标签: angularjs

我正在尝试创建一个应用程序(http://plnkr.co/edit/EVasje),它有两个步骤链接&基于示例http://jsfiddle.net/cfulnecky/NRUxs/的部分内容。

现在,如果你点击案例,我会得到一个案例列表,如果我点击任何案例,右边的面板会更新但只有一次。单击其他链接似乎不会重新加载部分。

知道我做错了什么吗? [此处代码示例的一部分]


var app = angular.module('plunker', []);

app.config(['$routeProvider', function($routeProvider) {    
    $routeProvider.when('/',                {template: { left : 'dashboard.html', right: ''}});
    $routeProvider.when('/cases',           {template: { left : 'cases.html', right: ''}});
    $routeProvider.when('/cases/view/:id',  {template: { left : 'cases.html', right: 'caseDetail.html'}});
    $routeProvider.when('/departments',        {template: { left : 'departments.html', right: ''}});
    $routeProvider.otherwise({redirectTo: '/'});     }]);

app.controller('AppController', ['$rootScope','$scope','$route', '$location','$controller', function ($rootScope,$scope,$route,$location,$controller) {            
    $rootScope.$on('$routeChangeStart', function(scope, newRoute, Current){                              
        if (!newRoute) return;                
        $rootScope.template = newRoute.$route.template;        
    });
    $scope.isActive = function(route) {      
        return route === $location.path();
    };      }]);    function CasesCtrl($scope,CaseFactory) {        $scope.cases = CaseFactory.getCases;   }

function CaseDetailCtrl($scope,$route) {    $scope.caseNum = $route.current.params.id; }

app.factory('CaseFactory', function() {   return {
    getCases:[{"project":{"id":3,"name":"Listings"},"updated_on":"2012-09-17T17:30:00Z","tracker":{"id":1,"name":"Bug"},"created_on":"2012-09-17T17:30:00Z","author":{"id":4,"name":"John Doe"},"id":22,"status":{"id":1,"name":"New"},"start_date":"2012-09-17","subject":"Check all the content with copy scape using APi","description":"","priority":{"id":4,"name":"Normal"}},{"project":{"id":3,"name":"Listings"},"updated_on":"2012-09-17T17:29:48Z","tracker":{"id":1,"name":"Bug"},"created_on":"2012-09-17T17:29:48Z","author":{"id":4,"name":"John Doe"},"id":21,"status":{"id":1,"name":"New"},"start_date":"2012-09-17","subject":"Scrap all the sites who have similar content","description":"","priority":{"id":4,"name":"Normal"}},{"project":{"id":6,"name":"Quran"},"updated_on":"2012-09-17T17:26:54Z","tracker":{"id":1,"name":"Bug"},"created_on":"2012-09-17T17:26:54Z","author":{"id":4,"name":"John Doe"},"id":20,"status":{"id":1,"name":"New"},"start_date":"2012-09-17","subject":"Add jQuery UI Layout to Admin Panel","description":"","priority":{"id":4,"name":"Normal"}}]     }; });

非常感谢帮助。

由于

1 个答案:

答案 0 :(得分:1)

似乎有一个问题不是重新加载部分,而是告诉角度它应该将新的路由id参数分配给范围。您必须告诉控制器观察路线并相应地更新范围。这将有效:

function CaseDetailCtrl($scope,$route, $rootScope) {
  $scope.caseNum = $route.current.params.id;  
  $rootScope.$on('$routeChangeSuccess', function(scope, newRoute, Current){                              
      $scope.caseNum = $route.current.params.id;     
  });
}

http://plnkr.co/edit/TaV3gT?p=preview