0

I am making a very basic angular app using ui-router, and I have 3 "modules" right now, which are home, login, and register. Here is how I have defined them:

'use strict'; var app = angular.module('exampleApp', [ 'ui.router', 'ngAnimate', 'ui.bootstrap' ]); app.config(function($stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise('/'); $stateProvider .state('home', { url: '/', templateUrl: './main/home/home.html', controller: './main/home/home-controller.js' }) .state('login', { url: '/login', templateUrl: './main/login/login.html', controller: './main/login/login-controller.js' }) .state('register', { url: '/register', templateUrl: './main/register/register.html', controller: './main/register/register-controller.js' }) }) 

However, I think I am doing the controller: portion wrong. I want to define each controller for each "module", and I'm not sure how to go about doing that.

Here's my file structure -

enter image description here

1 Answer 1

2

First define your controller.

angular.module('exampleApp').controller('loginCtrl', function () { // ctrl task goes here. }); 

Mapping controller to a route.

$stateProvider.state('login', { url: '/login', templateUrl: 'path/to/login.html', controller: 'loginCtrl' }) 
Sign up to request clarification or add additional context in comments.

2 Comments

will this controller go inside the app.module.js file then? that is the file in which i am defining the states. if so, i am wondering how can i put the controller in the login folder. thanks
You can do something like app.controller in the file where you have defined the app and the states, that will be if you are trying to learn the concept, but in practice, controllers are kept in separate js file.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.