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

Does angularJS have anything in place for lazyload of external JS / CSS files based on ng-controller namespaces? For the following to add com.myApp.SomeClass.js and com.myApp.SomeClass.css to the title of the document?

<div ng-controller="com.myApp.SomeClass"></div>
+5
source share
2 answers

Not yet, but it is in working message v1.0.

Is your application so big that you need? We have several impressively large applications, and we have not yet encountered this need, because the controllers are much denser than when writing the same behavior without angular.

+3
source

slowscript? lazyload angularjs

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

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

-

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 )

<div ng-controller="Sexy">
    <input list="univ">
        <datalist id="univ">
            <option ng-repeat="univ in univs" value="{{univ.name}}"></option>
        </datalist>
    </input>
    <input type="submit"></input>
    <noscript src="test.js" type="text/slowscript"></noscript>
</div>

test.js

require(['angular','slowscript'],function(angular,slowscript){
    slowscript.$global.sexy=(function($scope){
        console.log("tada~");
        $scope.univs = [{"idx": 1,"name": "asdf"}, {"idx": 2,"name": "bsdf"}];
        $scope.$apply();
    });
    slowscript.queue_execute();
});
0

All Articles