【问题标题】:Can't show single item on click Angular单击Angular时无法显示单个项目
【发布时间】:2016-06-18 17:50:01
【问题描述】:

当我想单击链接以显示单个模板(项目)时,出现以下错误:

警告:尝试多次加载 angular。

截图链接:http://i.imgur.com/ZZDEA3J.png

这是我的 templates.html 代码:

<div ng-repeat="template in filteredTemplates | filter:q" class="col-lg-4 col-md-6 col-sm-6 col-xs-12 portfolio-item">
  <h4>
      <a href="/edit/{{template.id}}" class="template-name"  >{{ template.name }} </a>
  </h4>
  <p>{{ template.content.substring(0, 40) | htmlToPlaintext | removeNbsp }} ...</p> 
  <div class="row">
      <div class="col-lg-6">
          <div ng-repeat="license in template.licenses">{{license.name}} prijs <i class="fa fa-eur" aria-hidden="true"></i> {{license | setPrice}}</div>
      </div>                                        
      <div class="col-lg-6">
          <a ng-click="placeOrder(template)"  class="btn btn-info" role="button"> Add to cart <span class="fa fa-cart-plus"></span></a>
      </div>
  </div>
</div>

app.js 代码:

//This will handle all of our routing
app.config(function($routeProvider, $locationProvider){
    $routeProvider.when('/', {
        templateUrl: 'js/templates/home.html',
        controller: 'HomeController'
    });

    $routeProvider.when('/templates', {
        templateUrl: 'js/store/templates.html',
        controller: 'TemplateController'
    });

    $routeProvider.when('/edit/:id', {
        templateUrl: 'js/store/template.html',
        controller: 'GetTemplateController'
    });

    $locationProvider.html5Mode({
        enabled: true,
        requireBase: false
    });
});

模板控制器.js:

template.controller('GetTemplateController', function ($scope, $routeParams, Template) {
      console.log('here');
});

我怀疑问题来自app.js 文件。有人知道我做错了什么吗?因为实在想不通

【问题讨论】:

  • 您看到的错误很可能是因为您在template.html 文件中列出了ng-app。然而,这只是一个猜测,因为您还没有显示该文件的内容。
  • @Claies 这是 template.html 链接的内容:i.imgur.com/Mrcr6Sg.png 我的 ng-app 在welcome.blade.php 中(我使用的是 Laravel)。这里是welcome.blade.php 链接的内容:pastebin.com/1jCy8KkY

标签: javascript html angularjs


【解决方案1】:

取自here:

您会注意到,如果应用程序找不到文件(即,否则),那么它将重定向到根目录,在这种情况下会加载 templateUrl。但是如果你的 templateUrl 是错误的,那么它会导致一个递归,一遍又一遍地重新加载 index.html 加载角度(以及其他所有内容)。

似乎是错误的模板 url 导致了这种情况。

【讨论】:

  • 我明白,但是应该找到文件 template.html 截图链接:i.imgur.com/T0NpDWc.png 如你所见,我在商店文件夹中有一个 template.html 文件。
  • 我能想到的另一件事是 angular script 标签出现了两次。
  • 在我的welcome.blade.php 文件链接中也不是这样:pastebin.com/1jCy8KkY 你可以看到我只展示了一次角脚本..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-02
  • 1970-01-01
相关资源
最近更新 更多