Typescript error on string functions in ionic application

Hi All ,

Getting typescript error on string functions such as split and length in ionic app
I get error when i am testing application locally using ionic serve.
Below is the code.

export class EarnResult {
  mesg : string;
  points : number;
  errCode : String;
  error : string;
  msgHdr : String ;
  msgDtl : String;
  constructor(public navCtrl: NavController, public navParams: NavParams) {
    this.mesg = this.navParams.get("mesg"); 
   let temp = this.mesg;
    let x = temp.length;
Error: Uncaught (in promise): TypeError: Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at new EarnResult (http://localhost:8100/build/0.main.js:82:21)
    at createClass (http://localhost:8100/build/main.js:11194:26)
    at createDirectiveInstance (http://localhost:8100/build/main.js:11028:37)
    at createViewNodes (http://localhost:8100/build/main.js:12377:49)
    at createRootView (http://localhost:8100/build/main.js:12282:5)
    at callWithDebugContext (http://localhost:8100/build/main.js:13413:42)
    at Object.debugCreateRootView [as createRootView] (http://localhost:8100/build/main.js:12874:12)
    at ComponentFactory_.create (http://localhost:8100/build/main.js:10219:46)
    at ComponentFactoryBoundToModule.create (http://localhost:8100/build/main.js:3800:29)
    at NavControllerBase._viewInit (http://localhost:8100/build/main.js:43144:44)
    at NavControllerBase._nextTrns (http://localhost:8100/build/main.js:42956:18)
    at NavControllerBase._queueTrns (http://localhost:8100/build/main.js:42913:14)
    at NavControllerBase._setPages (http://localhost:8100/build/main.js:42840:21)
    at http://localhost:8100/build/main.js:42823:26
    at t.invoke (http://localhost:8100/build/polyfills.js:3:14529)
    at g (http://localhost:8100/build/polyfills.js:3:7133)
    at l (http://localhost:8100/build/polyfills.js:3:6251)
    at http://localhost:8100/build/polyfills.js:3:6805
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15213)
    at Object.onInvokeTask (http://localhost:8100/build/main.js:4489:37)
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15134)
    at n.runTask (http://localhost:8100/build/polyfills.js:3:10390)
    at a (http://localhost:8100/build/polyfills.js:3:5313)
  • Ionic Framework: 3.0.1
  • Ionic App Scripts: 1.3.0
  • Angular Core: 4.0.0
  • Angular Compiler CLI: 4.0.0
  • Node: 6.10.1
  • OS Platform: Windows 7
  • Navigator Platform: Win32

i think you are not getting any value in mesg variable from navparam.

1 Like

yes . You are right .

I have parent- child pattern .

I was changing only child page and post saving in VsCode . It is loading only child page and executing the constructor . Since control has not come from parent page . It is giving error .

When control is coming from parent page , string functions are executing correctly . Thanks for quick pointer.