当我使用AngularJS 1.3.14时不读取JSON文件,但与1.2.10版本一起工作很好

Not reading JSON file when I use AngularJS 1.3.14 but works fine with version 1.2.10

本文关键字:但与 版本 很好 工作 一起 文件 读取 AngularJS 14时 JSON      更新时间:2023-09-26

我目前使用AngularJS 1.2.10,它工作得很好,但我想把它改成1.3.14来添加一个accordian。但是当我改变

<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.10/angular.min.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>

我的数据不再显示了。这是我的代码(它只是一个简单的搜索列表,我已经在HTML部分的底部注释了1.3.14版本)。

http://jsfiddle.net/xoonpLte/

Angular不再支持全局函数作为控制器了。

控制器必须声明为模块

的一部分

添加:

manuRep.controller('MyAppController', MyAppController);

你必须

  • 把名字放在ng-app
  • 用angular的
  • 匹配ui-bootstrap版本
  • 使用ui。bootstrap代替ui-bootstrap

这里它工作了(我还改变了声明控制器语法)

http://jsfiddle.net/xoonpLte/8/

var mr = angular.module('manuRep', ['ui.bootstrap']);
mr.controller('myctl', ['$scope', '$http', function ($scope, $http) {
    $http({
        method: 'GET',
        url: 'https://dl.dropboxusercontent.com/u/59954187/jobs.json'
    }).then(function (response) {
        $scope.cats = response.data;
    });
}])

这是我的解决方案。http://jsfiddle.net/xoonpLte/10/

var manuRep = angular.module('manuRep', ['ui.bootstrap']);
manuRep.controller('MyAppController', function($scope, $http) {
    $http.get('https://dl.dropboxusercontent.com/u/59954187/jobs.json').then(function(response) {
    $scope.cats = response.data;
});

});