javascript - requirejs + angularjs code structure split in different files -


i'm using requirejs , angular , i'm trying create application structure allows me split every controller/services/directives etc in different files. structure i'd achieve:

src/ components/     navigation/         index.js         module.js         navigationcontroller.js         navigationservice.js 

in module.js i'd this:

define(['angular', './navigationservice', './navigationcontroller'], function (angular, navigationservice, navigationcontroller) {     'use strict';     return angular.module('myapp.navigation', [])         .controller('navigationcontroller', navigationcontroller)         .service('navigationservice', navigationservice) }); 

and having controller/service definition defined in separated js file.

the issue don't know how define these files. i've tried syntax:

//navigationservice.js define( function() {              this.donavigation = function () {                 console.log('i navigating');             }     }); 

but doesn't working. have ever seen kind of structure using requirejs?

thanks!

try:

//navigationservice.js define([], function() {     navigationcontroller.$inject = ['$scope', '$q', 'myownservice', 'etc'];     function navigationcontroller($scope, $q, myownservice, etc) {         ...     }     return navigationcontroller; }); 

you may interested in angular-require-lazy.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -