Can two different modules have controllers with the same name in angular js?

I am making my first application in Angular JS.

I have three websites Tab.

So how should angular modules be defined ? One for each page and one main module that controls all three pages?

I wanted to ask if this is possible?

+4
source share
3 answers

, , ( / AngularJS).

angular , , .. , .

angular.module('app', [])
.controller("tab1", function() {
    })
.controller("tab2", function() {
    })
.controller("tab3", function() {
    });
+3

, . , .

.

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

.

app.controller("myCtrl", function($scope) {
   $scope.firstName = "John";
   $scope.lastName = "Doe";
});

. :)

+1

, . HTML- .

.


App.js

app.controller("PanelController", function() {
 this.tab = [youTabId]; // Set a tab by default on load. 

 this.selectTab = function(setTab) {
  this.tab = setTab;
 };

 this.isSelected = function(checkTab) {
  return this.tab === checkTab;
 };
});

HTML ng-controller ng-controller="PanelController as panel".

<li> ng-class, ng-class="{active : panel.isSelected([yourTabId])}".

<a> a ng-click, ng-click="panel.isSelected([youTabId])".

, <div>, , ng-show="panel.isSelected([yourTabId])"


.

+1

All Articles