2014-05-07 82 views
0

首先,我使用了一个模块“家庭”它工作正常。当我添加另一个模块“卖方”的第二部作品,但“家庭”不再工作了!如何声明2个模块

我认为第一个控制器被擦除,但第二个!!!?我不知道为什么!请帮帮我 。

angular.module('family', []); 

angular.module('family') 
    .controller('list', function($scope) { 
     $scope.family = "Family 1"; 
    }); 





angular.module('seller', []); 

angular.module('seller') 
    .controller('list', function($scope) { 
     $scope.seller = "Seller 1"; 
    }); 



angular.module('app', 
    [ 
     'ngRoute', 
     'family', 
     'seller' 
    ] 
    ); 

angular.module('app') 
    .config(
     ['$routeProvider', 
     function($routeProvider) { 
      $routeProvider.when('/family', {templateUrl: 'modules/family/views/index.html', controller: 'list'}); 
      $routeProvider.when('/seller', {templateUrl: 'modules/seller/views/index.html', controller: 'list'}); 

     }]); 
+2

使用不同的控制器名称或定义只是一个控制器。 Angular不知道你的意思是哪个控制器,在家庭模块或卖家模块上。它将使用它找到的第一个。 – Dieterg

+0

非常感谢,我在这里被拦截了3个多小时。现在我昵称,这个工作很完美。谢谢@DieterGoetelen – Mimouni

回答

0

只是为了关闭这个问题,@DieterGoetelen在评论中的回应解决了所有的问题。

和我的新的代码变成了:

angular.module('family', []); 

angular.module('family') 
    .controller('family.list', function($scope) { 
     $scope.family = "Family 1"; 
    }); 





angular.module('seller', []); 

angular.module('seller') 
    .controller('seller.list', function($scope) { 
     $scope.seller = "Seller 1"; 
    }); 



angular.module('app', 
    [ 
     'ngRoute', 
     'family', 
     'seller' 
    ] 
    ); 

angular.module('app') 
    .config(
     ['$routeProvider', 
     function($routeProvider) { 
      $routeProvider.when('/family', {templateUrl: 'modules/family/views/index.html', controller: 'family.list'}); 
      $routeProvider.when('/seller', {templateUrl: 'modules/seller/views/index.html', controller: 'seller.list'}); 

     }]);