Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SailsService throws - Cannot read property 'get' of undefined in angular-4 #15

Closed
Rj-s opened this issue May 4, 2017 · 4 comments
Closed

Comments

@Rj-s
Copy link

Rj-s commented May 4, 2017

It has some issue with Angular-4
package.json:-
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",

I followed example.md file but facing error :- Cannot read property 'get' of undefined(this._sailsService).

I would appreciate help.

Thanks

@joeherold
Copy link
Owner

how did you implement it?

@joeherold
Copy link
Owner

did you have a look at https://joeherold.gitbooks.io/angular2-sails/content/

@Rj-s
Copy link
Author

Rj-s commented May 5, 2017

Its my bad. I forgot to add this._sailsService.connect('http://X.X.X.XX:1337') just before subscribing the observable.
I had to set io.socket.url also before connection to avoid errors in console. It was establishing localhost connection if we dont set it.

io.socket.url = 'http://X.X.X.XX:1337'; 
this._sailsService.connect('http://X.X.X.XX:1337');

// This is to fetch all values. 
this._sailsService
  .get('/user')
  .subscribe(
  (resData) => {
    console.log(resData);
  },
  (error) => { console.log('Some error occured in socket-io', error); }
  );


// This is to observe changed values from server side. 
this._sailsService
  .on('user')
  .subscribe(
  (resData) => {
    console.log(resData);
  },
  (error) => { console.log('Some error occured in socket-io', error); }
  );

Thanks,

@joeherold
Copy link
Owner

fine. you are welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants