Ich mache einen MEANJS-Antrag. Ich habe einen AngularJS-Controller, in dem ich Snoocore verwenden möchte.
'use strict';
angular.module('core').controller('HomeController', ['$scope', 'Authentication', 'snoocore',function($scope, Authentication, Snoocore) {
// This provides Authentication context.
$scope.authentication = Authentication;
var reddit = new Snoocore({
userAgent: 'test@documentation',
oauth: {
type: 'implicit', // required when using implicit OAuth
mobile: true, // defaults to false.
key: '', // Only requires the key! No secret needed.
redirectUri: 'redirectUri set for your app',
scope: [ 'read', 'flair', 'identity' ] // make sure to set all the scopes you need.
}
});
}
]);
Ich habe Snoocore über Bower importiert. Es liegt in
public/lib/snoocore
Der Controller befindet sich in
public/modules/core/controllers/home.client.controller.js
Im Moment funktioniert das, was ich tue, nicht. Und ich bin ein bisschen ratlos. Ich bin noch sehr neu in Angular und dem MEANJS-System im Allgemeinen.
Die Konsole gibt Folgendes aus
Error: [$injector:unpr] Unknown provider: snoocoreProvider <- snoocore
http://errors.angularjs.org/1.2.28/$injector/unpr?p0=snoocoreProvider%20%3C-<section data-ui-view="" class="ng-scope">noocore
at http://localhost:3000/lib/angular/angular.js:78:12
at http://localhost:3000/lib/angular/angular.js:3801:19
at Object.getService [as get] (http://localhost:3000/lib/angular/angular.js:3929:39)
at http://localhost:3000/lib/angular/angular.js:3806:45
at getService (http://localhost:3000/lib/angular/angular.js:3929:39)
at invoke (http://localhost:3000/lib/angular/angular.js:3956:13)
at Object.instantiate (http://localhost:3000/lib/angular/angular.js:3976:23)
at http://localhost:3000/lib/angular/angular.js:7315:28
at chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:1544:22
at http://localhost:3000/lib/angular/angular.js:6711:34
3 Antworten
Ich habe das Tag hinzugefügt
<script src="/lib/snoocore/dist/Snoocore-browser.min.js"></script>
Zu meinem HTML-Kopf und änderte meinen Controller so, dass er wie folgt aussieht.
'use strict';
angular.module('core').controller('HomeController', ['$scope', 'Authentication' ,function($scope, Authentication) {
// This provides Authentication context.
$scope.authentication = Authentication;
var reddit = new Snoocore({
userAgent: 'test@documentation',
oauth: {
type: 'implicit', // required when using implicit OAuth
mobile: true, // defaults to false.
key: '', // Only requires the key! No secret needed.
redirectUri: 'redirectUri set for your app',
scope: [ 'read', 'flair', 'identity' ] // make sure to set all the scopes you need.
}
});
}
]);
Wenn Sie eine offizielle Bibliothek verwenden, können Sie die Abhängigkeit nicht als normales AngularJS-Modul einfügen, da es keinen AngularJS-Anbieter gibt.
Ich denke, Sie sollten die Bibliothek wie eine normale JS-Bibliothek verwenden:
var Snoocore = window.Snoocore;
'use strict';
angular.module('core').controller('HomeController', ['$scope', 'Authentication', function($scope, Authentication) {
// This provides Authentication context.
$scope.authentication = Authentication;
var reddit = new Snoocore({
userAgent: 'test@documentation',
oauth: {
type: 'implicit', // required when using implicit OAuth
mobile: true, // defaults to false.
key: '', // Only requires the key! No secret needed.
redirectUri: 'redirectUri set for your app',
scope: [ 'read', 'flair', 'identity' ] // make sure to set all the scopes you need.
}
});
}
]);
Versuchen Sie dies und ich hoffe, Ihr Problem zu lösen.
Snoocore
ist kein Winkelmodul, sodass Sie es nicht als Winkelabhängigkeit verwenden können. Erstellen Sie entweder einen Winkelservice / eine Winkelfabrik, um die Snoocore
zu verpacken, oder verwenden Sie die globale Variable window.Snoocore
. Stellen Sie außerdem sicher, dass Sie die Quelldatei Snoocore
in Ihren HTML-Code aufgenommen haben.