Angular ui.router only load one file, can't look elsewhere for templateUrl

时间:2017-04-06 17:10:18

标签: javascript angularjs angular-ui-router

I think I just don't understand something but here's my case : I'm using a view engine in my "app.js" file

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

Using ui-router, I'm currently declaring my states like this :

.state('home', {
      url: '/home',
      templateUrl: '/home.html',
      controller: 'MainCtrl',
      })

This state apparently look into my index.ejs file for something like:

<script type="text/ng-template" id="/home.html"> ...</script>

My "index.ejs" file is something like that:

<html>
 <body ng-app="PerformManagement" ng-controller="MainCtrl">
  <div class="container">
    <div >
      <!-- On appelle le template-->
    <ui-view></ui-view>
    </div>
  </div>
 </body>
</html>
<script type="text/ng-template" id="/home.html">...</script>
<script type="text/ng-template" id="/risks.html" ng-controller="RisksCtrl">...</script>

It works this way but I want to slice my index.ejs into different files because it start getting too big for me to work on properly. I call my template when changing state by this way, in index.ejs :

<div class="container">
    <div >
      <!--Template called-->
      <ui-view></ui-view>
    </div>
 </div>

I've created files like "home.html" where I put my html code, and I want my templateUrl load it. But passing something like templateUrl: 'home.html' doesn't work at all. I've tried to put my "home.html" in many places but still can't understand why it doesn't work. I'm pretty new working on Angular and Node so I think I've missed something. I followed this tutorial https://thinkster.io/tutorials/mean-stack/

I'm quite lost at the moment so if anybody could find a nice way to do that, I'll really appreciate.

0 个答案:

没有答案