Lazyload external JS/CSS files based on controller namespace convention?

Question!

Does angularJS have anything in place to lazyload external JS/CSS files based on ng-controller namespaces? So that the following would append com.myApp.SomeClass.js and com.myApp.SomeClass.css to the document head?

<div ng-controller="com.myApp.SomeClass"></div>
By : Lee Owen


Answers

how about using slowscript? It's really easy to lazyload on angularjs

Example: https://github.com/flrngel/slowscript-angular-require-lazyload

Slowscript: https://github.com/flrngel/slowscript

core code from website

app.js

app = angular.module("mainApp", ["ui.router"]).run(function($rootScope){
    $rootScope.$on('$viewContentLoaded',function(){
        slowscript.execute();
    });
});

app.config(function($stateProvider, $urlRouterProvider) {
    $stateProvider.state("sexy", {
        url: "/sexy",
        views: {
            "contents": {
                templateUrl: "/views/test.html",
                controller: "Sexy",
                reloadOnSearch: true
            }
        }
    });
});

app.controller("Sexy", function($scope) {
    slowscript.queue(function(){
        slowscript.$global.sexy($scope);
    });
});

test.html (angular view template)



This video can help you solving your question :)
By: admin