AngularJS - Controller & ngRoute

307 views Asked by At

Evening,

I'm using ngRoute + 1.3.5 at the moment, i have an admin page that has it's own admin view and controller.

I don't want the 'admin.js' script reference:

<script src="/Resources/Javascript/Controllers/ctrlAdmin.js"></script>

-in the index.html page - where the ng-view resides. I only want the route referenced (without injecting the controller).

.when('/admin', {
    templateUrl: '/resources/html/views/admin.html'
    // Look Mom, no controller reference........
})

If i include the reference to the 'admin.js' file within the view file, let's call it 'admin.html', i get a 'NaN function undefined'. However if i put it in the index.html page, all is great. I'd rather not, Angular is obviously trying to resolve all references before it loads, which is reasonable; but is there a way to do this cleanly?

2

There are 2 answers

0
NewZeroRiot On BEST ANSWER

Issue found here, it seems i didn't quite search enough.

https://github.com/angular/angular.js/issues/11384

0
Anton Bessonov On

I use following combo for lazy loading everything (js, css, controllers, translations etc., except html's, because is build in), partially for protected access:

For translations I have own implementation, which I would like to open source later. But angular-translate is good enough for most cases.

With this combo you need neither define (permission protected) js in index.html nor as dependency. Other positive effect is reduced download size.