1

I am devloping a single web page with angularJS. The page should display contents from another services which will return values as JSON.

I am using like below,

View file:

<div ng-app="phonecat">
   <div ng-view></div>
</div>

<div ng-app="tabletcat">
  <div ng-view></div>
</div>

app js file

angular.module('phonecat', []).
   config(['$routeProvider', function($routeProvider) {
   $routeProvider.
      when('', {templateUrl: 'partials/phone-list.html',   controller: PhoneListCtrl}).
      otherwise({redirectTo: '/phones'});
}]);

angular.module('tabletcat', []).
  config(['$routeProvider', function($routeProvider) {
      $routeProvider.
      when('', {templateUrl: 'partials/tablet-list.html',   controller: TabListCtrl}).
      otherwise({redirectTo: '/phones'});
 }]);

it displays the phone list properly. But it is not triggering the tablet list.

Suggest me the best practice to achieve this.

2

2 Answers 2

3

You can't use multiple ngApp directives in the same document, as mentioned by the documentation :

ngApp (directive in module ng ) Use this directive to auto-bootstrap an application. Only one directive can be used per HTML document.

You probably wanted rather have multiple controllers ?

Sign up to request clarification or add additional context in comments.

1 Comment

YES. I want to have multiple controller. Can you please guide me how to acheive it?
0

Given the markup:

<div id="phonecatElement">
  <div ng-view></div>
</div>

<div id="tabletcatElement">
  <div ng-view></div>
</div>

Use the following

angular.bootstrap($('#phonecatElement'), ["phonecat"]);
angular.bootstrap($('#tabletcatElement'), ["tabletcat"]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.