代码之家  ›  专栏  ›  技术社区  ›  Done job

如何在本项目中为ionic中的提供程序设置路径?

  •  0
  • Done job  · 技术社区  · 7 年前

    我正在用页面构建一个离子应用程序。。。正在尝试将提供程序导入about组件,但在应用程序中找到模块之前,无法找到该模块。组成部分ts \

    //我正在尝试将dbserviceprovider导入到大约。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();
          //   });
        });
    
      }
    
    
    }
    

    //项目结构是。。。 enter image description here

    在构建我的第一个ionic应用程序时,我陷入了这个困境。。我们将不胜感激。

    编辑:

    我所面临的问题是由于其他人修改了项目结构。

    2 回复  |  直到 6 年前
        1
  •  1
  •   necilAlbayrak    7 年前

    提供商的url应为 ../../providers/dbservice/dbservice 您需要输入这些相对于当前文件的URL。 在这种情况下,您试图在about中包含dbservice。ts文件。然后当你用../下次使用../您位于src中,其中还包括providers文件夹。然后键入提供者/数据库服务/数据库服务的路由

    有关相对路径的详细信息 Review this article

        2
  •  0
  •   Done job    7 年前
    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();
          //   });
        });
    
      }
    
    
    }