gpt4 book ai didi

javascript - AngularJS TypeError : d is undefined - Firefox, angular-route.min.js:7 Uncaught TypeError: 无法读取未定义的属性 'isArray' - Chrome

转载 作者:行者123 更新时间:2023-11-27 22:46:58 25 4
gpt4 key购买 nike

我正在开发一个基于 AngularJS 的响应式单页 Web 应用程序,显示一些数据,但我遇到了一个可能与 RequireJS 有关的问题。我在使用 Firefox 时收到 d is undefinedUncaught TypeError: Cannot read property 'isArray' of undefined,但刷新 Chrome 后一切看起来都正常(不适用于 Firefox) )。这是代码:

RequireJS 配置:

requirejs.config({
baseUrl: 'js',
paths: {
angular: [
'lib/angular.min',
'https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min'
],
angularRoute: [
'lib/angular-route.min',
'https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular-route.min'
]
}
});

脚本

define(['angular','angularRoute'], function($) {

var app = angular.module("myModule", ["ngRoute"])
.config(function($routeProvider) {
$routeProvider
.when("/home", {
templateUrl: "templates/home.html",
controller: "homeController"
})
.when("/repositories", {
templateUrl: "templates/repositories.html",
controller: "repositoriesController"
})
.when("/contributors", {
templateUrl: "templates/contributors.html",
controller: "contributorsController"
})
.otherwise({
redirectTo: "/home"
})
})
.controller("homeController", function($scope) {
$scope.headingOne = "App description";

})
.controller("repositoriesController", function($scope, $http, $log) {
$http.get('https://api.github.com/users/x-formation/repos')
.then(function(response) {
$scope.gitHub = response.data;
})
$scope.headingTwo = "X-Formation public repositories";
$scope.sortColumn = "forks_count";
$scope.reverseSort = true;

$scope.sortData = function(column) {
$scope.reverseSort = ($scope.sortColumn == column) ? !$scope.reverseSort : false;
$scope.sortColumn = column;
}

$scope.getSortClass = function (column) {
if ($scope.sortColumn == column) {
return $scope.reverseSort ? 'arrow-down' : 'arrow-up';
}
return '';
}
})
.controller("contributorsController", function($scope, $http) {
$http.get('http://cors.io/?u=https://www.x-formation.com/wp-content/uploads/2014/09/contributors.json')
.then(function(response) {
$scope.xFormationData = response.data;
})
$scope.headingThree = "Top contributors";
$scope.sortColumn = "contributions";
$scope.reverseSort = true;

$scope.sortData = function(column) {
$scope.reverseSort = ($scope.sortColumn == column) ? !$scope.reverseSort : false;
$scope.sortColumn = column;
}

$scope.getSortClass = function (column) {
if ($scope.sortColumn == column) {
return $scope.reverseSort ? 'arrow-down' : 'arrow-up';
}
return '';
}
})

});

我最近才开始,我觉得这有点超出我的范围,但我最终必须知道这一点。

最佳答案

代码中最引人注目的是 require 语句:

define(['Angular','AngularRoute'], function($) {

您需要传递 Angular,而不是 $ 符号。

此外,您的要求设置缺少一些垫片设置。关注这篇文章https://www.startersquad.com/blog/angularjs-requirejs/看看这是否能解决您的问题。

关于javascript - AngularJS TypeError : d is undefined - Firefox, angular-route.min.js:7 Uncaught TypeError: 无法读取未定义的属性 'isArray' - Chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38353169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com