0

I am initiating me in AngularJS and I have a doubt beginner.

I have defined my main module with several units already displayed on screen . I happen to have another module but do not know how to put it in the main module , because if I put it as a dependency , then the view gives me error. I have also doubts how to apply various ngcontroller in html, because the same thing happens , if I put the main everything works fine ... when I put the second module , and nothing works ... I guess that is dependence.

I leave my code and you will understand better. Thank you very much.

JS code ----------------------------------------------------

var app = angular.module('frutariaApp',
    ['ngMaterial', 'ngMessages']);
app.controller('AppCtrl', function($scope, $mdDialog, $mdMedia) {

(this is the part I don't know to implement over de main module).

   angular.module('acc-test', ['ui.bootstrap']);
   function AccordionCtrl($scope) {
    $scope.oneAtATime = true;
     }
});

HTML---------------------------

<html ng-app="frutariaApp">
<body ng-controller="AppCtrl">
 <div class="accordion-test" ng-controller="AccordionCtrl"> //Ihave problem with this too   
  <accordion close-others="oneAtATime">    
    <accordion-group is-open="falsee">      
        <accordion-heading>
            Number <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': isopen, 'glyphicon-chevron-right': !isopen}"></i>
        </accordion-heading>
             <ul>
          <li><a href="#">0</a></li>
            <li>1</li>          
      </ul>
    </accordion-group>
  </accordion>
</div>
</body>
</html>

Thanks

2
  • what is 'acc-test' doing in your code?. And why have you defined AccordionCtrl when you have already defined AppCtrl Commented May 21, 2016 at 16:59
  • why do you want to use bootstrap and angular material together? Commented May 21, 2016 at 17:00

1 Answer 1

1

In order to use modules other than the main one they must be injected as a dependency of another module.

Try injecting your 'acc-test' module into the main app module

var app = angular.module('frutariaApp',    ['ngMaterial', 'ngMessages', 'acc-test']);
Sign up to request clarification or add additional context in comments.

2 Comments

And the rest of code will be the same?? I mean, I continuos need this part of code? or angular.module('acc-test) dissapear??... (angular.module('acc-test', ['ui.bootstrap']); function AccordionCtrl($scope) { $scope.oneAtATime = true; })
Yes... can have as many modules as you want and as long as each one is injected as dependency of at least one other then they are all combined into one app. Then use any controller.... and can also use any service from any of the modules in other modules also since they are all one big app

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.