gpt4 book ai didi

javascript - 使用 angularAMD 时 ng-table 未正确加载

转载 作者:行者123 更新时间:2023-11-29 21:49:52 25 4
gpt4 key购买 nike

我将 angularAMD 与 requirejs 一起使用,当我尝试向 Controller 提供 ng-table 模块时,我收到 Uncaught TypeError: Cannot read property 'module' of undefined from the ng-table module。错误来源:

var app = angular.module('ngTable', []);

我的代码是:

'use strict';

requirejs.config({
paths: {
'angular': ['../lib/angularjs/angular'],
'angular-route': ['../lib/angularjs/angular-route'],
'angularAMD': ['../lib/angularAMD/angularAMD'],
'ng-table': ['../lib/ng-table/ng-table']
},
shim: { 'angularAMD': ['angular'], 'angular-route': ['angular'], 'ng-table': ['angular']}
});


define(['angularAMD', 'angular-route'], function (angularAMD) {
var app = angular.module("meadApp", ['ngRoute']);

app.config(function ($routeProvider) {
$routeProvider
.when("/results", angularAMD.route({
templateUrl: 'partials/results.html', controller: 'resultsController', controllerUrl: './controllers/resultsController'
}))
.otherwise({redirectTo: "/results"});
});

return angularAMD.bootstrap(app);
});

resultController.js

define(['app', 'ng-table'], function (app) {
app.controller('resultsController', function ($scope, $http) {
$scope.users = [
{name: "Moroni", age: 50},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34}
];
});
});

结果.html

<div>
<table ng-table class="table">
<tr ng-repeat="user in users">
<td data-title="'Name'">{{user.name}}</td>
<td data-title="'Age'">{{user.age}}</td>
</tr>
</table>
</div>

最佳答案

制作 Angular 形垫片并导出 Angular 形。像这样:

主要.js:

requirejs.config({
paths: {
'angular': ['../lib/angularjs/angular'],
'angular-route': ['../lib/angularjs/angular-route'],
'angularAMD': ['../lib/angularAMD/angularAMD'],
'ng-table': ['../lib/ng-table/ng-table']
},
shim: {
'angular': { exports: 'angular' },
'angularAMD': ['angular'],
'angular-route': ['angular'],
'ng-table': ['angular']}
});

我是从这里发现的:https://github.com/esvit/ng-table/pull/377#issuecomment-57934733


@marcoseu 的回答对我不起作用。我发现我也不需要 Restangular 的 ngload,这是在引导 Angular 之后加载的另一个第 3 方 Angular 模块。我不确定那是怎么回事,我一定不明白。

关于javascript - 使用 angularAMD 时 ng-table 未正确加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29830659/

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