【问题标题】:meteor-angular ui.router behaving strange流星角ui.router行为奇怪
【发布时间】:2016-02-25 01:38:36
【问题描述】:

我正在完成 angular 1 的流星角教程,并且在 routes.js 文件中遇到了一些问题。出于某种原因,这会适当地显示我的文件,但是当我从 templateUrl (client/parties/views/parties-list.html) 中的根目录添加适当的路径时,该文件不会显示。有人可以帮我理解为什么会这样。所有文档都说 templateUrl 路径是绝对的。谢谢。

客户端/routes.js

angular.module('socially').config(function($urlRouterProvider, $stateProvider, $locationProvider) {

$locationProvider.html5Mode(true);

$stateProvider
  .state('parties', {
    url: '/parties',
    templateUrl: 'parties-list.html',
    controller: 'PartiesListCtrl'
  })
  .state('partyDetails', {
    url: '/parties/:partyId',
    templateUrl: 'party-details.html',
    controller: 'PartyDetailsCtrl'
  });

$urlRouterProvider.otherwise("/parties");
});

client/party/views/parties-list.html

<form>
  <label>Name</label>
  <input ng-model="newParty.name">
  <label>Description</label>
  <input ng-model="newParty.description">
  <button ng-click="parties.push(newParty)">Add</button>
  <button ng-click="removeAll()">Remove All</button>
</form>
<ul>
  <li ng-repeat="party in parties">
    <a href="/parties/{{party._id}}">{{party.name}}</a>
    <p>{{party.description}}</p>
    <button ng-click="removeParty(party)">X</button>
  </li>
</ul>

【问题讨论】:

  • 模板文件有 404 错误吗?如果是这样,那应该告诉你路径有什么问题
  • 嘿菲尔。否定 404 错误。这是一个奇怪的问题。我试过重新启动服务器,甚至重新启动计算机。由于某种原因,router.js 仅路由到包含party-list.html 文件的初始路径。虽然,我已将文件移至 public/party/views 目录。

标签: angularjs meteor angular-ui-router


【解决方案1】:

client/party/views/parties-list.html

我更改了以下代码行:

<button ng-click="parties.push(newParty)">Add</button>

<button ng-click="parties.save(newParty)">Add</button>

并且路径变得绝对......这与绕过控制器并直接访问使路径成为绝对路径的mongo集合有关。不过,不知道为什么/怎么会这样。

【讨论】:

    猜你喜欢
    • 2014-07-09
    • 1970-01-01
    • 1970-01-01
    • 2015-06-15
    • 2016-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多