mean-expert-official / loopback-sdk-builder

Tool for auto-generating Software Development Kits (SDKs) for LoopBack
Other
399 stars 175 forks source link

Ref is not Defined #312

Closed roboflank closed 7 years ago

roboflank commented 7 years ago

What type of issue are you creating?

What version of this module are you using?

Write other if any:

Please add a description for your issue:

error_handler.js:53 TypeError: Cannot read property 'ref' of undefined at new SearchPage (search.ts:25) at new Wrapper_SearchPage (wrapper.ngfactory.js:7) at CompiledTemplate.proxyViewClass.View_SearchPage_Host0.createInternal (host.ngfactory.js:15) at CompiledTemplate.proxyViewClass.AppView.createHostView (view.js:81) at CompiledTemplate.proxyViewClass.DebugAppView.createHostView (view.js:341) at ComponentFactory.create (component_factory.js:154) at Tab.NavControllerBase._viewInit (nav-controller-base.js:407) at Tab.NavControllerBase._nextTrns (nav-controller-base.js:236) at Tab.NavControllerBase._queueTrns (nav-controller-base.js:207) at Tab.NavControllerBase.push (nav-controller-base.js:51)

My search.ts looks like: import { Component } from '@angular/core';` import { NavController, NavParams } from 'ionic-angular';

import { ItemDetailPage } from '../item-detail/item-detail'; import { Items } from '../../providers/providers'; import { Item } from '../../models/item'; import {FireLoopRef, Sms} from '../../sdk/models'; import { RealTime } from '../../sdk/services'; declare var window: any;

@Component({ selector: 'page-search', templateUrl: 'search.html' }) export class SearchPage { currentItems: any = []; public smses: any; currentSMS: any = []; private sms : Sms = new Sms(); private reference : FireLoopRef; constructor(public navCtrl: NavController, public navParams: NavParams, public items: Items, private rt: RealTime) { this.reference = this.rt.FireLoop.ref(Sms); }

What could be the issue?

Thanks.

jonathan-casarrubias commented 7 years ago

The problem is that in the latests versions youu need to create your references inside

this.realtime.onReady().subscribe((status: string) => { Here })

roboflank commented 7 years ago

Let me try and see the feedback

On Wed, Jan 11, 2017, 14:46 Jonathan Casarrubias notifications@github.com wrote:

The problem is that in the latests versions youu need to create your references inside

this.realtime.onReady().subscribe((status: string) => { Here })

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mean-expert-official/loopback-sdk-builder/issues/312#issuecomment-271848641, or mute the thread https://github.com/notifications/unsubscribe-auth/AGOuF7q-YLzeePD3Pbzt5qqV2e1PMF0Gks5rRMD6gaJpZM4LgMXg .

roboflank commented 7 years ago

@jonathan-casarrubias Where is this line exactly?

roboflank commented 7 years ago

Acded constructor(public navCtrl: NavController, public navParams: NavParams, public items: Items, private rt: RealTime) { // this.reference = this.rt.FireLoop.ref<Todo>(Todo); this.rt.onReady().subscribe((status: string) => {Todo}); } Then Pumped into another error,

error_handler.js:53 TypeError: Cannot read property 'on' of undefined at CompiledTemplate.proxyViewClass.View_SearchPage0.detectChangesInternal (component.ngfactory.js:285) at CompiledTemplate.proxyViewClass.AppView.detectChanges (view.js:288) at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (view.js:381) at CompiledTemplate.proxyViewClass.View_SearchPageHost0.detectChangesInternal (host.ngfactory.js:29) at CompiledTemplate.proxyViewClass.AppView.detectChanges (view.js:288) at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (view.js:381) at ViewRef.detectChanges (view_ref.js:130) at Tab.NavControllerBase._viewAttachToDOM (nav-controller-base.js:425) at Tab._viewAttachToDOM (tab.js:253) at Tab.NavControllerBase._transition (nav-controller-base.js:515)

jonathan-casarrubias commented 7 years ago

In that snippet you are not really creating a fireloop reference you are just adding the word Todo.

Im on my phone now so it is difficult to modify your snippet, but I encourage you to see the wiki docs here in the repo. It does states the correct way of registering references http://docs.fireloop.io/en/api/

roboflank commented 7 years ago

I've done that still same error.

jonathan-casarrubias commented 7 years ago

Ok that is strange, here you can find a running example: https://github.com/mean-expert-official/fireloop-todo-example

Not sure what your issue is, but that example does works, we are also working on projects for customers using it and does work, so just make sure you have the latest SDK Version, the latest Component Realtime Version.

Unfortunately that stack is not very informative, but usually the Cannot read property 'on' of undefined error is because you are trying to register an on listener before fireloop is already connected.

You should not have any this.reference.on() listener outside the onReady, so if you have for instance

  ngOnInit() {
    this.reference.on(); // This is wrong
  }

I hope this information helps you find your issue

roboflank commented 7 years ago

Thanks. Fixed the issue. Error was in the template where i had called,

<li *ngFor="let todo of reference.on('changes') | async">

roboflank commented 7 years ago

Am running into another error when trying to post data. :(

screenshot from 2017-01-13 08-42-55

jonathan-casarrubias commented 7 years ago

Hi @denzelwamburu would you mind to elaborate a little more your problem? is complex to advice you with the information you are providing.

Please provide an example of how are you using the API, also if you can parse the json [object Object] and see the actual result, it may be an ACL problem, but you need to read the actual error.

roboflank commented 7 years ago

This error comes after i try to post data to the endpoint.

roboflank commented 7 years ago

Here is my html : https://github.com/denzelwamburu/100/blob/engine/src/pages/search/search.html And ts : https://github.com/denzelwamburu/100/blob/engine/src/pages/search/search.ts

jonathan-casarrubias commented 7 years ago

this seems to be really straight forward implementation, I don't see anything wrong, though I'm assuming you are referring to the add method, which seems to be totally fine

You can debug this error by either adding a second callback within the create method that throws an error you can actually read, or you can also check the network tab within the developers console. In there filter the processes by selecting only websockets, and then find the socket connection and you can see the exact messages being passed.

Have you added ACL Rules in your back end models?

roboflank commented 7 years ago

Yeah, i implemented as per the api.

jonathan-casarrubias commented 7 years ago

Ok then it seems that your client does not hace permissions to call that method, have you tried to login a user prior trying to call the create method? You definitely need to follow the rule if you want to be able to call the method.

Not sure what the rule is but you need to address it, fireloop does implement the LoopBack security so if you add ACL rules, you need to follow these even if you use fireloop, it works just like the REST interface, you need to either make the create method public to everyone, or create a rule, make sure a logged user accomplish that rule and then you need to login that user within the fireloop client, then you will have access to call that method

roboflank commented 7 years ago

Hi @jonathan-casarrubias Thanks for your Help. I did redo the project again and seems to be fine now. Don't know what the issue was really.

jonathan-casarrubias commented 7 years ago

Ok cool Im glad you were able to fix your issue.

cheers! Jon