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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -