How to apply asynchronously fetched CSS into view


Tags: javascript,css,angularjs

Problem :

I'm fetchinh a html bundled view asynchronously (html+css+js) using AngularJS inside an Ionic project with the following code:

.controller('Main', function($scope, $http, $sce, $window) {

$http.get('URL').
success(function(data, status, headers, config) {
    $scope.ui = $sce.trustAsHtml(data.create_ui);
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});

});

The thing is that the provided CSS is using <link> tag and since the hml is injected, this links are never fetched and applied to style the view.

Is there any way to fetch or import these css and js scripts?

Thanks in advance, if more information is needed I'm willing to update.



Solution :

<link rel="stylesheet" ng-href="{{dynamicFile.href}}" type="{{dynamicFile.type}}"  />

You can set the dynamicFile in the callback.

.controller('Main', function($scope, $http, $sce, $window) {

$http.get('URL').
success(function(data, status, headers, config) {
    $scope.ui = $sce.trustAsHtml(data.create_ui);
    $scope.dynamicFile = data.dynamicFile;
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});

});

Also this would be helpful https://github.com/Yappli/angular-css-injector


    CSS Howto..

    How to add padding space in /div container via CSS?

    How to add an image to a CSS popup box

    How can I wrap this text so it doesn't overflow past the widget container?

    how to show the hidden div with same properties css with jquery

    how to align image and text when floating to image

    how to position element equally from left and right sides?

    How to make double lines border in CSS, each line in different color, without using background image?

    How to make two tooltip ids independently close, and remember cookie?

    How can I edit adjacent selector to a nested one

    how to set html inline css from django

    How to make a horizontal expandable menu fluid

    How to change CSS color values in real-time off a javascript slider?

    Inner div has borders - how to override with a class on an outer div?

    How to fade CSS sprite images using CSS background-position with jQuery?

    How to set the maximum height of CSS images?

    How to position footer correctly with css?

    How to override global style for img tag in css

    How do I make an image resize inside a div that is resizing to a percentage of a parent div?

    How to prevent CSS3 transform from make elements unclickable

    How to align div horizontally in this case

    How to apply an image to a CSS ordered list in WordPress?

    How can I set one style to override another conflicting style in CSS?

    How to target a CSS ID to a specific HTML tag [closed]

    How can I center a tooltip below an element that is narrower than the tooltip?

    How to create CSS for round, responsive, bootstrap button with border? Border is affecting pixels

    How do I enable scrolling only in one direction in CSS?

    How to target an element under an other element?

    How to put a ribbon image on another image with css?

    How to create custom border style in JavaFX CSS?

    How to create a fluidic list using css