为什么不在ng-view Angular JS中加载文件CSS / JS?

时间:2022-06-24 12:51:57

I use $routeProvider and load views HTML via <div ng-view></div>. In loaded file HTML there is HTML:

我使用$ routeProvider并通过

加载视图HTML。在加载的文件HTML中有HTML:

<script src="/public/js/tags/tokenize/jquery.tokenize.js"></script>
<link href="/public/js/tags/tokenize/jquery.tokenize.css" rel="stylesheet" type="text/css">

But these files are not connected in page. Also JS does not exicute on ng-view

但这些文件未在页面中连接。 JS也没有在ng-view上进行exicute

1 个解决方案

#1


This is because Angular thinks your <script> is the directive script. You have two possible solutions:

这是因为Angular认为您的

  • create a directive
  • 创建一个指令

  • include your code out of the app.
  • 从应用程序中包含您的代码。

If you need to dinamically load your resources use a service, as suggested in this question.

如果你需要动态加载资源,请使用服务,如本问题所示。

Also, for reference, take a look to this question too

此外,作为参考,也看看这个问题

#1


This is because Angular thinks your <script> is the directive script. You have two possible solutions:

这是因为Angular认为您的

  • create a directive
  • 创建一个指令

  • include your code out of the app.
  • 从应用程序中包含您的代码。

If you need to dinamically load your resources use a service, as suggested in this question.

如果你需要动态加载资源,请使用服务,如本问题所示。

Also, for reference, take a look to this question too

此外,作为参考,也看看这个问题