2

I am working on a Yeoman Angular-generated folder. I installed through Bower a module that requires jQuery. Grunt's wiredep places the jQuery dependency above the AngularJS in the index.html, as follows:

<!-- build:js(.) scripts/vendor.js -->
<!-- bower:js -->
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-animate/angular-animate.js"></script>
...
<!-- endbower -->
<!-- endbuild -->

This seems reasonable, as jQuery doesn't depend on Angular.

The thing is that when I try to load my app in the browser, I get the following message in JS console:

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
VM80711:26293 
WARNING: Tried to load angular more than once.

angular-animate.js:442 Uncaught TypeError: Cannot read property 'offsetWidth' of null

If I manually swap the jQuery dependency with the angular one at index.html, everything works like a charm, but when I grunt build my app, default order is set, so I can't get the working configuration in the dist folder.

bower.json:

{
  "name": "webapp",
  "version": "0.1.0",
  "dependencies": {
    "angular": "^1.3.0",
    "angular-animate": "^1.3.0",
    "angular-resource": "^1.3.0",
    "angular-sanitize": "^1.3.0",
    "angular-touch": "^1.3.0",
    "angular-ui-router": "~0.2.14",
    "angular-material": "~0.9.0",
    "restangular": "~1.5.1",
    "angular-slick": "~0.2.1",
    "ngInfiniteScroll": "~1.2.1"
  },
  "devDependencies": {
    "angular-mocks": "^1.3.0"
  },
  "appPath": "app",
  "moduleName": "app"
}

Really appreciate your help here!

4

1 回答 1

3

删除/重新排序 jquery.js 的替代方法:

如果您index.html正在使用,请<ui-view />尝试将其更改为:<ui-view></ui-view>由于 HTML5 如何处理标签,如this SO post about tag syntax

其次,请检查您的routes,如this SO post about错误地引用视图

示例: templateUrl: 'myView/myPage.html'检查拼写和大小写

于 2015-05-21T20:57:22.717 回答