从 1.1.0 升级到 1.1.1 后 Angular JS 失败 [英] Angular JS Fails After Upgrade from 1.1.0 to 1.1.1

查看:23
本文介绍了从 1.1.0 升级到 1.1.1 后 Angular JS 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我升级 ng-repeat 需要非常长的时间来加载并尝试在没有 $resource 提供的内容的情况下显示更多的内容框.

我已将问题缩小到 1.1.0 和 1.1.1 之间的更新.我查看了变更日志,但没有发现任何问题是罪魁祸首,但它肯定在那里.

Changelog =>

When I upgrade the the ng-repeat takes extraordinarily long to load and tries to display MORE content boxes without the content that is being served by $resource.

I have narrowed the problem down to the update between 1.1.0 and 1.1.1. I looked through the changelog but nothing popped out at me to be the culprit, but it must be in there.

Changelog => https://github.com/angular/angular.js/blob/master/CHANGELOG.md#111-pathological-kerning-2012-11-26

The repository for this app => https://github.com/brianpetro/resume

Currently my angular looks like:

app = angular.module("Resume", ["ngResource"])

app.factory "Entry", ["$resource", ($resource) ->
  $resource("/entries")
]

@EntryCtrl = ["$scope", "Entry", ($scope, Entry) ->
  $scope.entries = Entry.query()
]

This happens on multiple views with using ng-repeat:

<html ng-app="Resume">
  <div ng-controller="EntryCtrl">
    <ul>
      <li ng-repeat="entry in entries">
        {{entry.title}}
      </li>
    </ul>
  </div>
</html>

This is AngularJS version 1.1.0: This is AngularJS version 1.1.1:

解决方案

It's not entirely true that you have to add .json - at least not from my experience when I have switched from 1.0.x to 1.1.x.

In order to make Rails app return json without specyfing extension in URL for Angular 1.1.x you need to make angular add additional header to http request:

myModule.config(['$httpProvider', function ($httpProvider) {
    $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
}]);

Without that Rails by default renders whole HTML instead of returning JSON.

Github issue reflecting that

这篇关于从 1.1.0 升级到 1.1.1 后 Angular JS 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆