2012-10-20 74 views
0

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

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

任何想法我做错了什么? [代码样品的一部分在这里]


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

似乎有一个问题与其说与重装的部分,但角度讲,它应该分配新的路由标识参数去的范围。您必须告诉控制器观察路线并相应地更新范围。这将工作:

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

+0

嘿,我想通了这一点了。实际上,我在邮件列表中提出了同样的问题,但没有人回答。我完全按照你的建议做了。谢谢无论如何,我已经接受你的答案:) – Mahbub

+0

很好,你找到了解决方案。 :)如果你找到自己问题的答案,你应该将其作为答案作为进一步参考。你甚至可以接受你自己的答案! – Narretz

+0

其实我打算(就像我在谷歌邮件列表上所做的那样),我知道我可以回答我自己的问题,但看到你做了它,并认为我应该接受;) – Mahbub