V
V
Vlad1712015-04-26 18:34:02
css
Vlad171, 2015-04-26 18:34:02

Angularjs how external css and js are connected when using ng-view?

The essence of the question is as follows: there is a main site template, there are several views connected via ng-view. I'm trying to place a jquery gallery on one of them, but it doesn't want to work. sees neither jquery nor gallery styles. When transferring the whole economy to the main page without ng-view - everything works ....... I tried to connect styles and scripts on the view and, accordingly, the main page, combined it in different ways - it doesn't work. Before that, I worked mainly with Django - everything is easier there, of course. If there are connoisseurs, explain the rules for including external css and js in this case.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Goryachkin, 2015-04-26
@abaddon65

In general, here is an example of connecting a script in a view:

(function() {

  var app = angular.module('testApp', [
    'ngRoute'
  ]);

  app.config(function($routeProvider) {
    $routeProvider.when('/page', {
      templateUrl: 'test.tpl.html',
      controller: 'TestCtrl'
    });
  });
  
  app.controller('TestCtrl', function($scope) {
    console.log('тут уже можно пользоваться теми скриптами, которые подгрузили во вьюхе');
  });

})();

Content of test.tpl.html:
<div class="testView">
    <script src="testFunction.js"></script>
</div>

Well, testFunction.js:
document.addEventListener( "DOMContentLoaded", function () {
     alert('Меня подгрузили!!!');
}, false );
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question