CSS does not load into other views when routing in angularjs

Hey, so I am routing between views in Angularjs using routeProvider and ng-view. My problem is that my css does not load when changing the route. I tried to include Angular-css so that css can be included in every view, but it does not work. It loads to the first page loaded from ng-view (home.html), but when I link to another page, css stops loading.

index.html

<!DOCTYPE html>
<html lang="en" ng-app="myApp">
  <head>

    <script src="app/lib/jquery-3.0.0.js"></script>
    <link href="styles.css" rel="stylesheet" type="text/css" />

    <script src="app/lib/angular.min.js"></script>
    <script src="app/lib/angular-route.min.js"></script>
    <script src="app/lib/angular-css.min.js"></script>
    <script src="app/lib/app.js"></script>
  </head>
  <body>

    <main ng-view>
    </main>

  </body>

app.js

var myApp = angular.module('myApp', ['ngRoute', 'angularCSS']);
myApp.config(['$routeProvider', function($routeProvider){
$routeProvider
  .when('/login', {
    templateUrl: 'views/login.html',
    css: 'styles.css'
  })
  .when('/home', {
    templateUrl: 'views/home.html',
    css: 'styles.css'
  })
  .when('/signup', {
    templateUrl: 'views/signup.html',
    css: 'styles.css'
  })
  .when('/submitdish', {
    templateUrl: 'views/submitdish.html',
    css: 'styles.css'
  })
  .when('/login', {
    templateUrl: 'views/login.html',
    css: 'styles.css'
  })
  .otherwise({
    redirectTo: '/home',
    css: 'styles.css'
  });
}]);

home.html

<ul class="nav">
     <a align="center" href="views/home.html"><li>Home</li></a>
     <a align="center" href=""><li>About</li></a>
     <a align="center" href="#"><li>Contact</li></a>
  </ul>

<section class="container">
  <div class="left-half">
    <article>
      <a href="views/submitdish.html" class="Button">Sell a Dish</a>

      <p>Something Something Something about Selling your home-cooked dishes</p>
    </article>
  </div>
  <div class="right-half">
    <article>
      <a href="views/buydish.html" class="Button">Buy a Dish</a>
      <p>Yada yada yada buy food from your neighbors</p>
    </article>
  </div>
</section>
+4
source share
3 answers

Ok, I realized that the problem was that I was referencing other views using

<a href="views/submitdish.html" class="Button">Sell a Dish</a>

#/submitdish ( routeProvider)

<a href="#/submitdish" class="Button">Sell a Dish</a>
+1

var myApp = angular.module('myApp', ['ngRoute', 'angularCSS']);

var myApp = angular.module('myApp', ['ngRoute', 'door3.css']);

, 1.0.7

http://door3.imtqy.com/angular-css

CSS-, , .html css

    var myApp = angular.module('myApp', ['ngRoute', 'angularCSS']);

    myApp.config(['$routeProvider', function($routeProvider){

    $routeProvider
      .when('/login', {
        templateUrl: 'views/login.html',
        css: 'views/styles.css'
      }); 
}]);

,

var myApp = angular.module('myApp', ['ngRoute', 'angularCSS']);

        myApp.config(['$routeProvider', function($routeProvider){

        $routeProvider
          .when('/login', {
            templateUrl: 'views/login.html',
            css: 'Content/styles.css'
          }); 
    }]);
+1

$routeProvider $locationProvider "#" URL- - " hashbang".

, http://example.com/#/home templateURL .

, $locationProvider.html5Mode true.The URL- , http://www.example.com/base/path

:

$routeProvider
  .when('/path', {
   templateUrl: 'path.html',
});
$locationProvider
  .html5Mode(true);

HTML ( href )

<html>
  <head>
    <base href="/">
  </head>
  <body>
    <a href="/path">link</a> 
  </body>
</html>    
+1

All Articles