javascript - Angular applications powered by Requirejs - Argument '(contoller)' is not a function, got undefined? -


I am trying to work on an angular application driven by RequireJS, but I am not able to split control files I'm having an error of logic (contoller) 'is not a function, it has been undefined. Any ideas what I have done?

ap / main.js,

  need.config ({baseUrl: "", // alias library path. Angle 'path: {' domReady ':' bower_components 'Bower_components / angle / angle', 'angular-way': 'bower_components / angle path / angle-way', 'jquery': 'bower_components / jquery / district / jquery' / requirejs-domready / domReady ',' angular ' }, // Add angular module does not support outside the AMD box, put it in a shim Shim: {'angular': {export: 'angular'} 'angular path': {export: 'angular'}}, // Kickstart App Deposit: ['App / Bootstrap']}); Define  

app / app.js,

  (['angular', 'angular path', 'jquery'], function (ng, ngrut) ), $) {'Strict experiment'; Console.log ($ ('h1'). Length); Return ng.module ('app', ['ngRoute']). Config (['$ routeProvider', function ($ routeProvider) {$ routeProvider.when ('/ home', {templateUrl: 'see / home.html', administrator: 'HomeCtrl', controllerUrl: 'application / home'}) ; $ RouteProvider.when ('/ View1', {templateUrl: 'see / view1.html', controller: 'View1Ctrl', controllerUrl: 'app / view'}); //$routeProvider.otherwise( {redirectTo: '/ Home'});}]);}) ; Define (['app / app'], function (app) {app.controller ('HomeCtrl')  

app / home.js,

 , 'Function ($ scope) {$ scope.message = "Message from homecuts";});}); Error: [ng: isq] Logic 'HomeCtrl' is not a function, it is undefined  

but if I type ng.module (' App ', [' ngRoute ']). Config (...) then they work fine,

app /app.js,

  define (['angular', 'angular' Route ',' jquery '], function (ng, ngrut, $) {' strict use '; console.log ($ (' h1 ') length.); Return ng.module (' app ', [' ngRoute '] Config ([' $ routeProvider ', function ($ routeProvider) {$ routeProvider.when (' / home '., {TemplateUrl:' see / home.html ', administrator:' HomeCtrl ', // controllerUrl:' $ RouteProvider.when ('/ View1', {templateUrl: 'see / view1.html', controller: 'View1Ctrl', // controllerUrl: 'app / view'}); // $ routeProvider .otherwise ({redirectTo: '/ home'});}]). Controller ('Homecattle', 'Funk Section ($ scope) {$ scope.message = "message Homkut";}). Controller ( 'View1Ctrl', function ($ scope) {$ scope.message = "message ViewlCtrl";});});  

Why

This is a problem load of your JS files Orders are defining HomeCtrl in the app / home.js, and it's using app / app.js so make sure that home.js is before in your web app loading of app.js.

Divide the app.js into two parts - just to create the NGMU (module .js), and to install a config (module-config.js). Then there will be dependency tree:

  app / module-config.js is required: app / home.js is required: app / module JS  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -