angularjs - How to split angular code in two script file for single page application -


i have single page application want split code in 2 separate js files, - script1.js -

 var app = angular.module("angularjs", ["ui.router"])                      .config(function ($stateprovider) {                          $stateprovider                            .state("home", {                               url:"/home",                                templateurl: "template/home.html",                                controller: "homecontroller",                                controlleras: "homectrl"                            })                         .state("courses", {                             url: "/courses",                             templateurl: "template/courses.html",                             controller: "coursescontroller",                             controlleras: "coursectrl"                         })                                                        .state("newregistration", {                                     //  url: "/students",                                    templateurl: "template/newregistration.html",                                     controller: "newregistration",                                     controlleras: "newregistrationctrl"                                 })                                            }) 

i have defined controller state

    .controller("homecontroller", function () {          this.message = "home page";      })             .controller("coursescontroller", function () {                 this.courses = ["c#", "vb.net", "sql server", "asp.net"];                 this.message = "courses page";             })  problem want define other controller on other script file -  script2.js -     .controller("newregistration", function () {     this.meassage = "new employee registration sfdsf"; })     

how separate code 2 different js files.

example of separation

app.js

var app = angular.module("angularjs", ["ui.router"]) 

config.js

app.config(function ($stateprovider) {                          $stateprovider                            .state("home", {                               url:"/home",                                templateurl: "template/home.html",                                controller: "homecontroller",                                controlleras: "homectrl"                            })                         .state("courses", {                             url: "/courses",                             templateurl: "template/courses.html",                             controller: "coursescontroller",                             controlleras: "coursectrl"                         })                                                        .state("newregistration", {                                     //  url: "/students",                                    templateurl: "template/newregistration.html",                                     controller: "newregistration",                                     controlleras: "newregistrationctrl"                                 })                                            }) 

controllers.js

app.controller("homecontroller", function () {          this.message = "home page";      }) app.controller("coursescontroller", function () {                 this.courses = ["c#", "vb.net", "sql server", "asp.net"];                 this.message = "courses page";             }) 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -