John Lindquist の多くのビデオに示されているように、ルートを変更する前にアプリにデータを収集させようとしています: http://www.youtube.com/watch?v=P6KITGRQujQ&list=UUKW92i7iQFuNILqQOUOCrFw&index=4&feature=plcp
私はそれをすべて接続しましたが、遅延オブジェクトが解決するときが来たら、エラーが発生します:
Error: Argument 'fn' is not a function, got Object
at assertArg (http://localhost:9000/components/angular/angular.js:1019:11)
at assertArgFn (http://localhost:9000/components/angular/angular.js:1029:3)
at annotate (http://localhost:9000/components/angular/angular.js:2350:5)
at invoke (http://localhost:9000/components/angular/angular.js:2833:21)
at Object.instantiate (http://localhost:9000/components/angular/angular.js:2874:23)
at http://localhost:9000/components/angular/angular.js:4759:24
at <error: illegal access>
at Object.Scope.$broadcast (http://localhost:9000/components/angular/angular.js:8261:28)
at http://localhost:9000/components/angular/angular.js:7417:26
at wrappedCallback (http://localhost:9000/components/angular/angular.js:6797:59) angular.js:5704
私のコードは次のようになります。
ルート -
angular.module( 'saApp' )
.config( function ( $routeProvider, $locationProvider ) {
$routeProvider
.when( '/dashboard', {
templateUrl: 'views/dashboard/dashboard.html',
controller: Dashboard,
resolve: Dashboard.resolve
}
});
コントローラー -
var Dashboard = angular.module( 'saApp' ).controller(
function ( $scope, dataset ) {
$scope.data = dataset;
} );
Dashboard.resolve = {
dataset: function ( $q, DBFactory ) {
console.log("dataset enter")
var deferred = $q.defer();
DBFactory.get( {noun: "dashboard"},
function ( data ) {
console.log("resolving");
deferred.resolve( data );
} );
console.log("promise");
return deferred.promise;
}
}
実行すると、解決が実行され、DBFactory リソースが移動して戻ってきて、実際の「deferred.resolve(data);」まですべてが機能します。これは、上に貼り付けられたエラーが表示される場所です。その1行をコメントアウトすると、もちろんページは表示されませんが、エラーも表示されません。
DBFactory から返されるデータの内容は JSON オブジェクトであり、これは予期されたものであり、私がオンラインで見たすべての例とビデオに示されています。
使用:
AngularJS 1.0.6
考え?ご助力いただきありがとうございます。
アップデート:
ルートを使用し、名前空間でコントローラーを定義していた方法のようです:
var Dashboard = angular.module( 'saApp' ).controller()
これのせいでした。標準の関数宣言を使用するだけの場合:
function DashboardCtrl($scope, dataset) {
$scope.data = dataset;
}
「関数を探して、オブジェクトを取得しました」というエラーを満たします。奇妙なことは、それをオブジェクト「var DashboardCtrl = angular.module('saApp').controller()」として使用するように変更したこと、または以前に持っていたものをyeomanジェネレーターから使用するように変更し、angularjsドキュメントで指定したことですの:
angular.module( 'saApp' )
.controller( 'DashboardCtrl', function ( $scope, dataset ) {});
次のルートで:
.when( '/dashboard', {
templateUrl: 'views/dashboard/dashboard.html',
controller: 'DashboardCtrl'
} )
うまくいきません。