This code in AngularJS using angular-local-storage throws an error at the console :
angular.module('myTodoApp').controller('MainCtrl', ['$scope', 'localStorageService ', function($scope, localStorageService) {
}]);
throws an error at the console :
Error: [$injector:unpr] Unknown provider: localStorageService Provider <- localStorageService <- MainCtrl
http://errors.angularjs.org/1.4.7/$injector/unpr?p0=localStorageService%20Provider%20%3C-%20localStorageService%20%20%3C-%20MainCtrl
at http://localhost:9000/bower_components/angular/angular.js:68:12
at http://localhost:9000/bower_components/angular/angular.js:4289:19
at Object.getService [as get] (http://localhost:9000/bower_components/angular/angular.js:4437:39)
at http://localhost:9000/bower_components/angular/angular.js:4294:45
at getService (http://localhost:9000/bower_components/angular/angular.js:4437:39)
at invoke (http://localhost:9000/bower_components/angular/angular.js:4469:13)
at Object.instantiate (http://localhost:9000/bower_components/angular/angular.js:4486:27)
at http://localhost:9000/bower_components/angular/angular.js:9151:28
at link (http://localhost:9000/bower_components/angular-route/angular-route.js:977:26)
at invokeLinkFn (http://localhost:9000/bower_components/angular/angular.js:8789:9)
...but this runs perfectly fine!, may I know why?
angular.module('myTodoApp').controller('MainCtrl', function($scope, localStorageService) {
});
Related
The LoggedInUser works well as it is suppose but whenever the app starts and the URL is queried like trying to login or navigate to any other URL, the Accounts.onLogin throws the below error. I don't know what could be the reason.
var LoggedInUser = FlowRouter.group({
name: 'currentUser', triggersEnter: [function () {
if (!Meteor.loggingIn() || !Meteor.userId()) {
var currentRoute = FlowRouter.current();
if (!currentRoute.route.name === 'home') {
console.log(currentRoute.path);
Session.set('redirectAfterLogin', currentRoute.path);
}
FlowRouter.go('home');
}
}]
});
Accounts.onLogin(function () {
let redirect = Session.get('redirectAfterLogin');
if (redirect) {
if (redirect != 'home') {
FlowRouter.go(redirect);
}
}
});
Error on cmd console
I20171003-18:28:44.913(1)? Exception in onLogin callback: ReferenceError: Session is not defined
I20171003-18:28:44.919(1)? at lib/routes/routes.js:30:18
I20171003-18:28:44.921(1)? at runAndHandleExceptions (packages\callback-hook.js:152:24)
I20171003-18:28:44.926(1)? at packages\callback-hook.js:159:12
I20171003-18:28:44.931(1)? at packages/accounts-base/accounts_server.js:164:5
I20171003-18:28:44.934(1)? at [object Object]._.extend.each (packages\callback-hook.js:128:15)
I20171003-18:28:44.938(1)? at AccountsServer.Ap._successfulLogin (packages/accounts-base/accounts_server.js:163:21)
I20171003-18:28:44.943(1)? at AccountsServer.Ap._attemptLogin (packages/accounts-base/accounts_server.js:353:10)
I20171003-18:28:44.946(1)? at [object Object].methods.login (packages/accounts-base/accounts_server.js:530:21)
I20171003-18:28:44.949(1)? at packages\check.js:128:16
I20171003-18:28:44.953(1)? at [object Object].EVp.withValue (packages\meteor.js:1135:15)
The onLogin function you are using needs the Session package according to the following line :
let redirect = Session.get('redirectAfterLogin');
The error in the console states than the Session package can not be found. Please make sure of the following:
Meteor Session is installed. If not please install it with:
meteor add Session
in your terminal in your project folder.
Session is imported in the file you want to use it, if not please add at the top of your file :
import { Session } from 'meteor/session'
I am trying to Http GET from a database , where I do have access and can reproduce the GET result in Postman.
I have created a service in angular2 {N} where I execute this GET but I get an error of :
JS: EXCEPTION: Error: Uncaught (in promise): Response with status: 200 for URL: null
JS: STACKTRACE:
JS: Error: Uncaught (in promise): Response with status: 200 for URL: null
JS: at resolvePromise (/data/data/org.nativescript.ndemo/files/app/tns_modules/zone.js/dist/zone-node.js:496:32)
JS: at resolvePromise (/data/data/org.nativescript.ndemo/files/app/tns_modules/zone.js/dist/zone-node.js:481:18)
JS: at /data/data/org.nativescript.ndemo/files/app/tns_modules/zone.js/dist/zone-node.js:529:18
JS: at ZoneDelegate.invokeTask (/data/data/org.nativescript.ndemo/files/app/tns_modules/zone.js/dist/zone-node.js:314:38)
JS: at Object.NgZoneImpl.inner.inner.fork.onInvokeTask (/data/data/org.nativescript.ndemo/files/app/tns_modules/#angular/core/src/zone/ng_zone_impl.js:37:41)
JS: at ZoneDelegate.invokeTask (/data/data/org.nativescript.ndemo/files/app/tns_modules/zone.js/dist/zone-node.js:313:43)
JS: at Zone.runTask (/data/data/org.nativescript.ndemo/files/app/tns_modules/zone.js/dist/zone-node.js:214:48)
JS: at drainMicroTaskQueue (/data/data/org.nativescript.ndemo/files/app/tns_modules/zone.js/dist/zone-node.js:432:36)
JS: Unhandled Promise rejection: Response with status: 200 for URL: null ; Zone: angular ; Task: Promise.then ; Value: Response with status: 200 for URL: null
JS: Error: Uncaught
(in promise): Response with status: 200 for URL: null
My service :
import { Headers, Http } from '#angular/http';
import 'rxjs/add/operator/toPromise';
export function createNonJsonResponse(http: Http, fullUrl: string): Promise<string>{
return http.get(fullUrl)
.toPromise()
.then(response => response.text())
// .catch(this.handleError);
}
I have logged both the URL given in and the Http and they are fine.
I have no idea why is this happening and google couldn't help me find any solutions whatsoever.
It seems, at least for me, #angular/core Http module is not working as intended. I switched to the nativescript's Http service (https://docs.nativescript.org/cookbook/http) and managed to accomplish what I needed without any problems.
Are you injecting the service somewhere? Add #Injectable() above the export. What if you change how you write the service a little and see if you receive the same response?
#Injectable()
export class createNonJsonResponse {
fullUrl: string = 'http://httpbin.org/get';
constructor(private http: Http) {}
getNonJsonResponse() {
return this.http.get(this.fullUrl)
.toPromise()
.then(response => response.text())
.catch(this.handleErrors);
}
}
Then import it to your component
import {createNonJsonResponse} from "./yourservicename.service"
And finally call it
this.createNonJsonResponse.getNonJsonResponse().then(function (data) {
alert("here");
//console.log(data);
//console.dump(data);
})
This worked for me I was able to hit my alert.
My angular controller looks like this:
angular.module("campos").controller("HomeCtrl", ['$scope', '$meteor', '$rootScope', '$state', '$modal',
function ($scope, $meteor, $rootScope, $state, $modal) {
// $scope.users = $meteor.collection(Meteor.users, false).subscribe('users');
$meteor.autorun($scope, function () {
$scope.$meteorSubscribe('myOrgnization', 'crown').then(function () {
$scope.organization.forEach(function (org) {
console.log(org._id);
});
},
function (error) {
console.log(error);
});
});
$scope.organization = $meteor.collection(function(){
return Organizations.find({});
});
}
]);
The server code looks like :
Meteor.publish('myOrgnization', function(org){
return Organizations.find({
'code' : org
});
});
The client controller finished properly, from the console I can get the the record id properly. However, I got an exception thrown out:
TypeError: undefined is not a function
at http://localhost:8026/packages/urigo_angular.js?de756130fe1ce5aaa41d3967997c1b2090bcdd1b:390:12
at Array.forEach (native)
at Function._.each._.forEach (http://localhost:8026/packages/underscore.js?46eaedbdeb6e71c82af1b16f51c7da4127d6f285:149:11)
at diffArray (http://localhost:8026/packages/urigo_angular.js?de756130fe1ce5aaa41d3967997c1b2090bcdd1b:388:5)
at updateCollection (http://localhost:8026/packages/urigo_angular.js?de756130fe1ce5aaa41d3967997c1b2090bcdd1b:1310:3)
at http://localhost:8026/packages/urigo_angular.js?de756130fe1ce5aaa41d3967997c1b2090bcdd1b:1154:11
at http://localhost:8026/packages/angular_angular.js?feeaf4750c9fd3ceafa9f712f99a21ee6fef9b41:17819:31
at completeOutstandingRequest (http://localhost:8026/packages/angular_angular.js?feeaf4750c9fd3ceafa9f712f99a21ee6fef9b41:5529:10)
at http://localhost:8026/packages/angular_angular.js?feeaf4750c9fd3ceafa9f712f99a21ee6fef9b41:5806:7
home.ng.js:8 dPmZoCeJ9YbKxKA4u
It seems coming from angular defer, but I think I am following the subscribe syntax properly ? even I change it to use $meter.subscribe, it throws the same exception.
Any help will be much appreciated.
Thanks in advance.
You should assign the $scope collection after the promise returns:
$scope.$meteorSubscribe('myOrgnization', 'crown').then(function () {
$scope.organization = $scope.$meteorCollection(function(){
return Organizations.find({});
});
});
I would also suggest passing an object for your publish arguments:
$scope.$meteorSubscribe('myOrginization', {arg1: 'crown'}).then(...)
Then of course on the server you would get:
Meteor.publish('myOrgnization', function(org){
return Organizations.find({
'code' : org.arg1
});
});
Inside my server, I that checks some data from the database and throws an error when it's not valid. I have it like so:
//SERVER CODE:
Meteor.methods({
send: function (prefix, number, content) {
Future = Npm.require('fibers/future');
var future = new Future();
//do some validation
myReference.doSomething({
number: number,
content: content
}, function(error) {
if(error) {
future.throw("Cannot send at this time.");
} else {
future.return("SUCCESS");
}
});
return future.wait();
}
});
In the client side, I would like to get the message "Cannot send at this time." inside future.throw("Cannot send at this time.");. Hopefully I could show it inside an alert. How do I do that?
Currently, this is what I'm trying and I keep getting some undefined error.
//CLIENT CODE
Meteor.call("send", prefix, number, content, function(err, result) {
if(err) {
console.log(err);
alert(err);
} else {
console.log("SUCCESSFULLY SENT. ", result);
}
});
This is the error I get when trying to get the error message:
errorClass: Internal server error [500]
{
error: 500,
reason: "Internal server error",
details: undefined, message: "Internal server error [500]",
errorType: "Meteor.Error"…}
details: undefined
error: 500
errorType: "Meteor.Error"
message: "Internal server error [500]"reason:
"Internal server error"stack: (...)get
stack: function () { [native code] }set stack:
function () { [native code] }__proto__: Middle
How do I get the error message that I threw from future?
Use it like that: return future.throw(new Meteor.Error(400, 'ololo'))
future.throw expects an Meteor.Error instance that in it's turn contains error message itself and additionally http response code. So 400 is Bad Request response code in that case and ololo is error message.
return isn't actually necessary here but I do it every time just to be sure I don't call any code after failure.
when I'm trying to use the http module to access nonexistent host, like this:
requestToRemote = http.createClient(80, 'fjasdfhasdkfj.vvvxcz').request(
method,
path,
headers
);
But I get the following error:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: getaddrinfo ENOENT
at errnoException (dns.js:31:11)
at Object.onanswer [as oncomplete] (dns.js:140:16)
I'd like to catch this error, so I've tried try/catch and setting the error listeners of a bunch of request properties, but none of if worked. How can I catch the error?
Looks like the error is thrown from http.Client, not the request. How about something like:
var site = http.createClient(80, host);
site.on('error', function(err) {
sys.debug('unable to connect to ' + host);
});
var requestToRemote = site.request(...);
FYI, http.createClient has been deprecated -- the following should work using the get convenience method:
http.get({host: host}, function(res) {
...
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
you could try and resolve the host using the dns module before running your code.
http://nodejs.org/docs/latest/api/dns.html#dns.resolve