I have a ŧest.json file:
{
"general":
{
"css": [
"css/test.css"
],
"js": [
"js/test.js"
]
}
}
and the following code for my angularjs app:
$stateProvider
.state('home', {
url: '/',
templateUrl: 'views/test.html',
resolve: {
loadAssets: ['DynamicService', function (DynamicService) {
return DynamicService.get();
}]
}
})
and here is my service to get file content as js object:
.factory('DynamicService', ['$resource', '$q', '$http',
function ($resource, $q, $http) {
var dynService = {};
var dynUrl = 'api/dynService'; // API to get "ŧest.json" file content
var error = function (response) {
// ...
};
dynService.get = function () {
return $http
.get(dynUrl)
.then(function (response) {
return response.data;
}, error);
};
return dynService;
}]);
I would like to dynamically load those files css/test.css and js/test.js files, taken after reading the ŧest.json file, before completing router initialization, so that, when visiting /, those files will be injected to DOM.
As you can see, I tried that code in $stateProvider but it does not work.
Any help please?
I have angularjs v1.7.0
Thanks