Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Hi I am new to angular js. and i am trying to separate js files in to many functional pieces. and i made a controller out side of app.js and it is not working =(

here is a code of app.js

'use strict';

angular.module('app', [
  'ui.rotuer',
  'app.controller'
]).config(function ($stateProvider,$urlRouterProvider) {
    $urlRouterProvider.otherwise("/");
    $stateProvider
        .state('home', {
            url: '/',
            templateUrl: 'home/views/home.html',
            controller: 'MyCtrl1'
          })
        .state('contact', {
            url: '/contact',
            templateUrl: 'home/views/contact.html',
          });
});

and

here is my controller part.

'use strict';

/* Controllers */
angular.module('app.controller', [])
  .controller('MyCtrl1', ['$scope', function($scope) {
    $scope.message="this is message from controller";
  }]);

i attached both files in html files. so both are loaded in html. and each view (html files) are available.

how do i make it right?

share|improve this question
    
First of all ui-router is mispelled. Secondly, did you put the scripts in the correct order? –  JoshSGman Jun 21 at 1:45
    
haha it is so embarrassing. it was from 'ui.router'. i checked it quite several times but it was .. Thanks a lot =) @JoshSGman –  Hanjun koo Jun 21 at 1:48
    
and the order thing, i need to put app.js first, right? –  Hanjun koo Jun 21 at 1:48
    
The order might not actually matter in this case, but If it does, it would make more sense if app.js loads after app.controller module, given that app.js is dependent on app.controller –  JoshSGman Jun 21 at 1:53
    
If you don't mind, can you vote up my answer, if it fixed it for you? THanks! –  JoshSGman Jun 21 at 1:55
add comment

1 Answer 1

up vote 0 down vote accepted

You have misspelled ui-router, additionally, make sure that that app.js is loading after you have defined app.controller in your scripts.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.