0

I am building an ionic application with pages ...trying to import a provider into about component but unable to find the module while it is till finding the module in app.component.ts \

//I am trying to import dbserviceprovider into about.ts

    import { Component } from '@angular/core';
    import { DbserviceProvider } from '../app/src/providers/dbservice/dbservice';//error is in this line
    import { NavController } from 'ionic-angular';

    export class dat {
      "name": String;
      "topic": String;
      "img": String;
      "description": String;
    }
    @Component({
      selector: 'page-about',
      templateUrl: 'about.html'
    })
    export class AboutPage {

      data: dat[];
      data_dbyes: any[];
      data_yes: any[]
      day: String[];
      temp: String = "../assets/imgs/logo.png";
      constructor(private dbser:DbserviceProvider,public navCtrl: NavController) {
        alert(dbser.test);
        this.data = [{
          "name": "Amil Nayar",
          "topic": "NodeJS",
          "img": "assets/imgs/nodejs.png",
          "description": "Node.js is an open-source, cross-platform JavaScript run-time environment for executing JavaScript code server-sid"
        },
        {
          "name": "Amil Nayar",
          "topic": "NodeJS",
          "img": "assets/imgs/nodejs.png",
          "description": "Node.js is an open-source, cross-platform JavaScript run-time environment for executing JavaScript code server-sid"
        },
        {
          "name": "Priya",
          "topic": "Ionic",
          "img": "assets/imgs/ionic.jpg",
          "description": "Ionic is a complete open-source SDK for hybrid mobile app development. The original version was released in 2013 and built on top of AngularJS and Apache Cordova."
        }
        ];
        this.data_yes = [{
          "name": "Maimuna Fatima",
          "topic": "Html 5",
          "img": "assets/imgs/html5.png",
          "description": "HTML5 is a markup language used for structuring and presenting content on the World Wide Web."
        },
        {
          "name": "Afifa khan",
          "topic": "Bootstrap",
          "img": "assets/imgs/bootstrap.jpg",
          "description": "Bootstrap is a free and open-source front-end web framework for designing websites and web applications"
        }
        ];
        this.data_dbyes = [{
          "name": "Rajendar",
          "topic": "jQuery",
          "img": "assets/imgs/jquery.jpg",
          "description": "jQuery is a cross-platform JavaScript library designed to simplify the client-side scripting of HTML."
        },
        {
          "name": "Priya",
          "topic": "Ionic",
          "img": "assets/imgs/jquery.jpg",
          "description": "jQuery is a cross-platform JavaScript library designed to simplify the client-side scripting of HTML."
        }
        ];
        console.log(this.data[0].name);
      }

    }


        [**enter image description here**][1]


  [1]: https://i.stack.imgur.com/eWvL3.png




but the same import is working in app.component.ts ...


//app.component.ts

import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';
import { TabsPage } from '../pages/tabs/tabs';

import { DbserviceProvider } from '../providers/dbservice/dbservice';
@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage: any = TabsPage;
  // private dbrecords: any[];


  constructor(private dbservice:  DbserviceProvider, platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, private sqlite: SQLite) {

    platform.ready().then(() => {
      alert(this.dbservice.test);
      // dbservice.dbconnect();
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      // this.dbrecords = [
      //   {
      //     name: 'hello',
      //     num: 23
      //   }
      // ];

      // this.sqlite.create({
      //   name: 'data.db',
      //   location: 'default'
      // })
      //   .then((db: SQLiteObject) => {

      //     // alert("sqlite object is created and value of db is "+db);

      //     db.executeSql('create table danceMoves(name VARCHAR(32),num INTEGER)', {}).then(() => {
      //       alert("hello db created");
      //       db.executeSql('insert into danceMoves(name,num) values("NCG",43)', {}).then(() => {
      //         // db.executeSql('select * from danceMoves',{}).then((res)=>{
      //         //   alert("in select statment"+res);
      //         // })
      //         db.executeSql('select * from danceMoves', {}).then((res) => {
      //           this.dbrecords[0]['name'] = res.rows.item(0).name;
      //           this.dbrecords[0]['num'] = res.rows.item(0).num;
      //           alert("length is "+res.rows.length);
      //         })
      //         alert("in insert " + this.dbrecords);
      //       })
      //     })
      //       .catch(e => alert("in catch" + e + this.dbrecords));
      statusBar.styleDefault();
      splashScreen.hide();
      //   });
    });

  }


}

//project structure is ...enter image description here

I am stuck at this while building my first ionic application ..help would be appreciated.

Edit:

The issue that I was facing was due to the project structure which was modified by someone else.

Done job
  • 59
  • 8
  • I added your answer below to solve problems like that easily i suggest using an ide with intellisense support like visual studio code which works great with typescript as well ass filepath support – necilAlbayrak Jan 20 '18 at 20:35

2 Answers2

1

Your url for provider should be ../../providers/dbservice/dbservice You need to enter these urls relative to your current file. In this case you are trying to include your dbservice on your about.ts file. Then when you go up one level with ../ you are in the pages folder when you go up another time with ../ you are in src which also includes providers folder. Then you type your route for providers/dbservice/dbservice

for more information on relative paths Review this article

necilAlbayrak
  • 824
  • 6
  • 9
0
import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';
import { TabsPage } from '../pages/tabs/tabs';
//edit is the next line
import { DbserviceProvider } from '../../providers/dbservice/dbservice';
@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage: any = TabsPage;
  // private dbrecords: any[];


  constructor(private dbservice:  DbserviceProvider, platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, private sqlite: SQLite) {

    platform.ready().then(() => {
      alert(this.dbservice.test);
      // dbservice.dbconnect();
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      // this.dbrecords = [
      //   {
      //     name: 'hello',
      //     num: 23
      //   }
      // ];

      // this.sqlite.create({
      //   name: 'data.db',
      //   location: 'default'
      // })
      //   .then((db: SQLiteObject) => {

      //     // alert("sqlite object is created and value of db is "+db);

      //     db.executeSql('create table danceMoves(name VARCHAR(32),num INTEGER)', {}).then(() => {
      //       alert("hello db created");
      //       db.executeSql('insert into danceMoves(name,num) values("NCG",43)', {}).then(() => {
      //         // db.executeSql('select * from danceMoves',{}).then((res)=>{
      //         //   alert("in select statment"+res);
      //         // })
      //         db.executeSql('select * from danceMoves', {}).then((res) => {
      //           this.dbrecords[0]['name'] = res.rows.item(0).name;
      //           this.dbrecords[0]['num'] = res.rows.item(0).num;
      //           alert("length is "+res.rows.length);
      //         })
      //         alert("in insert " + this.dbrecords);
      //       })
      //     })
      //       .catch(e => alert("in catch" + e + this.dbrecords));
      statusBar.styleDefault();
      splashScreen.hide();
      //   });
    });

  }


}
Done job
  • 59
  • 8