错误:输入未定义当Ajax请求从php获取数据时Angular

时间:2015-07-14 17:07:33

标签: php ajax angularjs

我正在尝试从角度js向php发出ajax请求。但我没有得到我通过php文件发送的数据。

我收到此错误:

  

错误:输入未定义

我的来源:

文件app.js:

 (function () {
var app = angular.module('myApp', ['ngRoute']);

app.config(function ($routeProvider) {
    $routeProvider

            .when('/', {
                controller: 'contentsCtrl',
                templateUrl: 'views/contents.php'
            })

            .when('/jalse/:jalseId', {
                controller: 'recordsCtrl',
                templateUrl: 'views/jalse.php'
            })

            .otherwise({redirectTo: '/'});
});

}());

文件view.html:

<div class="content-panel">
<div class="content-panel-title">
    <a href="#/records/" class="left"></a>
    <h2>  {{jalse.contentDate }}</h2>
</div>

<div ng-repeat="jalse in records">
    {{jalse.contentDate }}
</div>

档案jalseFactory.js:

    (function () {

'use strict';

var jasleFactory = function ($http, $q) {

var factory = {};

factory.getJalse = function () {
    var deferred = $q.defer();

    $http({method: 'GET', url: 'includes/records.php'}).
            success(function (data, status, headers, config) {
                deferred.resolve(data);
            }).
            error(function (data, status, headers, config) {
                deferred.reject(data);
            });
    return deferred.promise;
  };
return factory;
};

jasleFactory.$inject = ['$http', '$q'];
angular.module('myApp').factory('jasleFactory', jasleFactory);

}());

文件recordsCtrl.js:

(function () {
'use strict';

var recordsCtrl = function ($scope, $http, $routeParams) {
    var jalseId = $routeParams.jalseId;

    $scope.records = jasleFactory.getJalse();

    $scope.jalse = null;

    function init() {
        for (var i = 0, len = $scope.records.length; i < len; i++) {
            if ($scope.records[i].contentID == parseInt(jalseId)) {
                $scope.jalse = $scope.records[i];
                break;
            }
        }
    }

    init();

};

}());

0 个答案:

没有答案