Cannot render view nativescript angular after http call


#1

Hi there, i cannot render view after a http call in 2 layer child module. but i can get value through console.


#2

Few things:

  1. Angular discourages providing services directly onto your components I think in RC5 or RC6. Those providers should live on the module declaration.
  2. Always name services with pascal case (i.e. RetrieverService).
  3. You should not have to change the default changeDetection that is inherited by Angular’s core.
  4. If variables are public you do not need to specify they are public, it’s inferred by the compiler.
  5. If you are specifying a default value on a variable, you do not need to specify it’s type.
  6. Your API calls should not have to run inside a ngZone.run function.
  7. You implement AfterViewInit, but never appear to implement the interface’s default function ngAfterViewInit.

Try resolving at least: 1, 3, 6 and possibly 7 and see if your problem persists.


#3

Thank for advice!.i able to get the view right now but it prop another error as below:
JS: ERROR TypeError: Cannot read property ‘statusText’ of undefined
JS: ERROR CONTEXT [object Object]
JS: ERROR TypeError: Cannot read property ‘statusText’ of undefined
JS: ERROR CONTEXT [object Object]
JS: ERROR Error: Uncaught (in promise): TypeError: Cannot read property ‘statusText’ of undefined
JS: TypeError: Cannot read property ‘statusText’ of undefined
JS: at Object.eval [as updateRenderer] (ng:///LayoutModule/LayoutComponent.ngfactory.js:18:59)


#4

Without providing the code where you are outputting a variable statusText, it is hard to help you debug. The error is thrown when you are accessing properties on an object that has not been defined.

For example:

Incorrect:

test: any;
console.log(test.statusText);

Correct:

test: any = {};
console.log(test.statusText);
test.statusText = 'Updated and Set';
console.log(test.statusText);

Optionally in your views you can use the syntax sugar for making sure it’s defined, using the ?.

<Label [text]="test?.statusText"></Label>

or you can use an *ngIf condition for when it is defined.

<Label *ngIf="test" [text]="test.statusText"></Label>

#5

Thank for saving my time :smile