[Typescript] Property '' does not exist on type || Cannot find name ''

Hi!

When I run my app for the first time with ionic cordova run browser -l, I get a lot of errors, but when I edit any file and save it, my app reloads and it works OK. Why is that?

ionic cordova run browser -l

ionic-app-scripts serve --address 0.0.0.0 --port 8100 --livereload-port 35729 --dev-logger-port 53703 --nobrowser --iscordovaserve --platform browser --target cordova
[app-scripts] [20:02:03] ionic-app-scripts 3.2.4
[app-scripts] [20:02:03] watch started …
[app-scripts] [20:02:03] build dev started …
[app-scripts] [20:02:03] clean started …
[app-scripts] [20:02:03] clean finished in 15 ms
[app-scripts] [20:02:03] copy started …
[app-scripts] [20:02:04] deeplinks started …
[app-scripts] [20:02:04] deeplinks finished in 429 ms
[app-scripts] [20:02:04] transpile started …
[app-scripts] [20:02:16] typescript: src/pages/addproducts/addproducts.ts, line: 25
[app-scripts] [20:02:16] typescript: src/pages/login/login.ts, line: 45
[app-scripts] [20:02:16] typescript: src/pages/login/login.ts, line: 47
[app-scripts] [20:02:16] typescript: src/pages/products/products.ts, line: 50
[app-scripts] [20:02:16] typescript: src/pages/products/products.ts, line: 53
[app-scripts] [20:02:16] typescript: src/pages/tabs-controller/tabs-controller.ts, line: 14
[app-scripts] Cannot find name ‘ModalComponent’.
[app-scripts] L24: @ViewChild(“productexpdate”) productexpdate;
[app-scripts] L25: @ViewChild(‘AddproductsPage’) modal: ModalComponent;
[app-scripts] Property ‘loggedIn’ does not exist on type ‘LoginPage’.
[app-scripts] L44: console.log('Is Logged in : ', isLoggedIn);
[app-scripts] L45: this.loggedIn = isLoggedIn;
[app-scripts] Property ‘loggedIn’ does not exist on type ‘LoginPage’.
[app-scripts] L47: if (this.loggedIn){
[app-scripts] L48: this.navCtrl.setRoot(ProductsPage);
[app-scripts] Property ‘product’ does not exist on type ‘ProductsPage’.
[app-scripts] L49: .subscribe(data => {
[app-scripts] L50: this.product = data.products;
[app-scripts] L51: loader.dismiss()
[app-scripts] Property ‘product’ does not exist on type ‘ProductsPage’.
[app-scripts] L52: // console.log(this.product);
[app-scripts] L53: return this.product;
[app-scripts] Cannot find name ‘ListaPage’.
[app-scripts] L13: tab1Root: any = ProductsPage;
[app-scripts] L14: tab2Root: any = ListaPage;
[app-scripts] L15: tab3Root: any = ContatoPage;

[INFO] Development server running!

   Local: http://localhost:8100
   External: http://192.168.1.5:8100

   Use Ctrl+C to quit this process

cordova run browser
[app-scripts] [20:02:16] watch ready in 12.56 s
[app-scripts] [20:02:16] copy finished in 12.49 s
[cordova] startPage = index.html
[cordova] Static file server running @ http://localhost:8000/index.html
[cordova] CTRL + C to shut down

Guys? Anyone? :frowning:

Can you put code for products.ts and tabs-controller.ts

  • It’s too difficult to decipher without those files in full

Hi! Thank you for your response.
I took addproducts.ts and tabs-controller.ts off because I fixed the issues.

products.ts (lines 51 and 53):

import { Component, ElementRef, ViewChild } from '@angular/core';
import { Http, Headers, RequestOptions } from '@angular/http';
import { IonicPage, NavController, NavParams, AlertController } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import { Platform } from 'ionic-angular';
import { LoadingController } from 'ionic-angular';
import { MenuController, Modal, ModalController, ModalOptions } from 'ionic-angular';
import { AddproductsPage } from '../addproducts/addproducts';
import { ProductdetailsPage } from '../productdetails/productdetails';
import { ToastController } from 'ionic-angular';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';

import 'rxjs/add/operator/map';
      
  
@IonicPage()
@Component({
  selector: 'page-products',
  templateUrl: 'products.html',
})



export class ProductsPage {

  constructor(public navCtrl: NavController, public alertCtrl: AlertController, public navParams: NavParams,
	      private http: Http, private storage: Storage, public plt: Platform, public loading: LoadingController,
	      private menu : MenuController, public modalCtrl: ModalController, public toastCtrl: ToastController) {
        this.menu.enable(true);
  }


ionViewDidLoad() {
	var headers = new Headers();
    headers.append("Accept", 'application/json');
    headers.append('Content-Type', 'application/json' );  
    let options = new RequestOptions({ headers: headers });
	
    this.getProducts();
  }
	  
getProducts() {
    let loader = this.loading.create({
		content: 'Preenchendo lista...',
    });
    loader.present().then(() => {
	this.http.get('http://192.168.1.5/itens/products.php')
		.map(res => res.json())
		.subscribe(data => {
			this.product = data.products;
			loader.dismiss()
			return this.product;
		},
		err => {
			loader.dismiss();
			console.log(err);
						let alert = this.alertCtrl.create({
						title:"Ops",
						subTitle:"Houve um erro de conexão. Certifique-se de que você está conectado e o banco de dados está acessível.",
						buttons: ['OK']
						});
					alert.present();				
			});
    });
} 
 
addProducts() {
	let profileModal = this.modalCtrl.create(AddproductsPage);
	profileModal.present();
	}
	 
removeProduct(item) {
	console.log (item);
	if(item.quantity<1){
		let alert = this.alertCtrl.create({
		title:"Ops",
		subTitle:"O produto já está zerado no estoque!",
		buttons: ['OK']
		});
	alert.present();
	}
	else {
		var headers = new Headers();
		headers.append("Accept", 'application/json');
		headers.append('Content-Type', 'application/json' );
		let options = new RequestOptions({ headers: headers });
 
		let data = {
		productid: item.id,
		productquantity: item.quantity
		};
		
		console.log (data);		
		this.http.post('http://192.168.1.5/itens/removeproducts.php',data, options)		
		.subscribe(res => {
			if(res){
			
				let toast = this.toastCtrl.create({
					message: 'Item consumido',
					duration: 2000,
					cssClass: "toastCss"
				});
			
				toast.present()
				setTimeout(() => {
					this.getProducts();
				}, 500);
			}
		},
		err => {
			console.log(err);
						let alert = this.alertCtrl.create({
						title:"Ops",
						subTitle:"Houve um erro de conexão. Certifique-se de que você está conectado e o banco de dados está acessível.",
						buttons: ['OK']
						});
					alert.present();				
			});
	
	}
}
  
refillProduct(item) {
  let alert = this.alertCtrl.create({
    title: 'Reabastecer estoque',
	message: 'Quanto?',
    inputs: [
      {
        name: 'refillquantity',
        placeholder: 'insira a quantidade...',
		type: 'int'
      }      
    ],
    buttons: [
      {
        text: 'Cancelar',
        role: 'cancel',
        handler: data => {
          console.log('Cancel clicked');
        }
      },
      {
        text: 'OK',
        handler: data => {
          if (data.refillquantity<1) {
          } else {
			var headers = new Headers();
			headers.append("Accept", 'application/json');
			headers.append('Content-Type', 'application/json' );
			let options = new RequestOptions({ headers: headers });
 
			let dt = {
				productid: item.id,
				productquantity: item.quantity,
				productrefill: data.refillquantity
			};
		
			console.log (dt);		
			this.http.post('http://192.168.1.5/itens/refillproducts.php',dt, options)		
			.subscribe(res => {
				if(res){
			
					let toast = this.toastCtrl.create({
						message: 'Item abastecido',
						duration: 2000,
						cssClass: "toastCss"
					});
			
					toast.present()
					setTimeout(() => {
						this.getProducts();
					}, 500);
				}
			},
			err => {
				console.log(err);
						let alert = this.alertCtrl.create({
						title:"Ops",
						subTitle:"Houve um erro de conexão. Certifique-se de que você está conectado e o banco de dados está acessível.",
						buttons: ['OK']
						});
					alert.present();				
			});
            return true;
          }
        }
      }
    ]
  });
  alert.present();
}

detailProduct(item) {
	let profileModal = this.modalCtrl.create(ProductdetailsPage,{'item': item});
	
	profileModal.present();
	
}
}

login.ts (lines 45 and 47):

import { Component, ViewChild } from '@angular/core';
import { NavController, AlertController } from 'ionic-angular';
import { CadastrarPage } from '../cadastrar/cadastrar';
import { MapaPage } from '../mapa/mapa';
import { MenuController } from 'ionic-angular';
import { Http, Headers, RequestOptions } from '@angular/http';
import { LoadingController } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import { Platform } from 'ionic-angular';
import { AuthServiceProvider } from './../../providers/auth-service/auth-service';
import { AddproductsPage } from '../addproducts/addproducts';
import { ProductsPage } from '../products/products';
  
      
@Component({
  selector: 'page-login',
  templateUrl: 'login.html'
})


export class LoginPage {

@ViewChild("username") username;

@ViewChild("password") password;
data:string;
  constructor(public navCtrl: NavController, public alertCtrl: AlertController, private menu : MenuController,
              private http: Http, public loading: LoadingController, private storage: Storage, public plt: Platform,
	      public authService: AuthServiceProvider) {
	this.menu.enable(false);
  }
  goToCadastrar(params){
    if (!params) params = {};
    this.navCtrl.push(CadastrarPage);
  }

signUp(){
this.navCtrl.push(CadastrarPage);
}
ionViewCanEnter() {
let loggedIn = <any>{};

this.storage.get('isLoggedIn').then((isLoggedIn) => {
    console.log('Is Logged in : ', isLoggedIn);
   this.loggedIn = isLoggedIn;

if (this.loggedIn){
	this.navCtrl.setRoot(ProductsPage);
        this.menu.enable(true);
}


});

}


signIn(){
if(this.username.value=="" ){
let alert = this.alertCtrl.create({
title:"ATTENTION",
subTitle:"Username field is empty",
buttons: ['OK']
});
alert.present();
} else
if(this.password.value==""){
let alert = this.alertCtrl.create({
title:"ATTENTION",
subTitle:"Password field is empty",
buttons: ['OK']
});
alert.present();
}
else
{
var headers = new Headers();
headers.append("Accept", 'application/json');
headers.append('Content-Type', 'application/json' );
let options = new RequestOptions({ headers: headers });
let data = {
username: this.username.value,
password: this.password.value
};
let loader = this.loading.create({
content: 'Processing please wait…',
});

loader.present().then(() => {
this.http.post('http://192.168.1.5/itens/login.php',data,options)
.map(res => res.json())
.subscribe(res => {
console.log(res)
loader.dismiss()
if(res=="Your Login success"){
let alert = this.alertCtrl.create({
title:"CONGRATS",
subTitle:(res),
buttons: ['OK']
});
this.navCtrl.setRoot(ProductsPage);
this.menu.enable(true);
this.storage.set('isLoggedIn', 'true');
alert.present();
}else
{
let alert = this.alertCtrl.create({
title:"ERROR",
subTitle:"Your Login Username or Password is invalid",
buttons: ['OK']
});
alert.present();
}
});
});
}
}
}

Okay, I think I managed to fix them:
On login.ts, I declared isloggedIn:boolean; outside my function and it worked;
On products.ts, I declared product: any; outside my function and it worked too.