私はrequirejsでangularAMDを使用しています.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}
];
});
});
results.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>