1

我是Angular的新手...

我创建了一个定义了一些路由的应用程序:

app = angular.module("LgiClient", ['ngCookies', 'buildings','ngResource']).config(['$routeProvider', '$locationProvider' ,
($routeProvider, $locationProvider) ->
  #$locationProvider.hashPrefix('');
  $locationProvider.html5Mode true
  $routeProvider.when("/",
    controller: "RaffleCtrl"
    templateUrl: "<%= asset_path('raffle/index.html') %>"
  ).when("/buildings", 
    controller: BuildingsIndexCtrl
    templateUrl: '<%= asset_path("buildings/index.html") %>'
  ).when("/buildings/new",
    controller: BuildingsCreateCtrl
    templateUrl: '<%= asset_path("buildings/new.html") %>'
  ).when("/buildings/:id",
    controller: BuildingsShowCtrl
    templateUrl: '<%= asset_path("buildings/show.html") %>'
  ).when("/buildings/:id/edit",
    controller: BuildingsEditCtrl
    templateUrl: '<%= asset_path("buildings/edit.html") %>'
  ).otherwise redirectTo: "/"
])

当我遵循这条路线“/buildings/:id/edit”时,它会转到这个模板:

<form name="editBuilding">
  <fieldset>
    <legend>
      Edit Building
    </legend>
      <div ng-include src="'buildings/form.html'"></div>
    <div class="form-actions">
      <button class="btn btn-success" ng-click="save()"
        ng-disabled="isClean() || editBuilding.$invalid">
        Save
      </button>
      <button ng-click="destroy()"
              ng-show="building.id"
              class="btn btn-danger">
              <i class="icon-trash"></i>Delete
      </button>
      <a href="/buildings" class="btn">
        Back to buildings
      </a>
    </div>
  </fieldset>
</form>

ng-include 指令引用位于同一目录中的另一个文件。

但是,当我运行此页面时,它不起作用。ng-include 找不到包含,因为它发出了错误的请求:

http://127.0.0.1:3000/buildings/1/buildings/form.html

代替

http://127.0.0.1:3000/buildings/buildings/form.html"

我怎样才能解决这个问题?

谢谢!

4

0 回答 0