错误:未捕获(承诺):TypeError:Object(...)不是函数TypeError:Object(...)不是函数

时间:2019-08-23 07:59:42

标签: angular ionic-framework ionic3

我正在尝试在离子应用程序中添加语音识别,但是添加语音识别时出现以下错误

使用的版本:- 离子框架-3.9.2 ionic-app-3.1.2 角核-5.0.0

我仅在新的ionic3初始化应用中添加了语音识别。

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import {SpeechRecognition} from '@ionic-native/speech-recognition/ngx';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';

@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    SpeechRecognition,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

app.module.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import {SpeechRecognition} from '@ionic-native/speech-recognition/ngx';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  bgcolor: string = "white";

  constructor(public navCtrl: NavController,private speechRecognition: SpeechRecognition ) {

  }

  ngOnInit(){

    this.speechRecognition.hasPermission()
    .then((hasPermission: boolean)=>{
      if(!hasPermission){
        this.speechRecognition.requestPermission().then(
          () => console.log('Granted'),
          () => console.log('Denied')
        )
      }
    })
  }

  start(){
    this.speechRecognition.startListening().subscribe(
      (matches: Array<string>)=>{
        this.bgcolor = matches[0]
      }
    )
  }

}

home.ts

{
  "name": "old",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "5.0.0",
    "@angular/compiler": "5.0.0",
    "@angular/compiler-cli": "5.0.0",
    "@angular/core": "5.0.0",
    "@angular/forms": "5.0.0",
    "@angular/http": "5.0.0",
    "@angular/platform-browser": "5.0.0",
    "@angular/platform-browser-dynamic": "5.0.0",
    "@ionic-native/core": "4.3.2",
    "@ionic-native/speech-recognition": "^4.20.0",
    "@ionic-native/splash-screen": "4.3.2",
    "@ionic-native/status-bar": "4.3.2",
    "@ionic/storage": "2.1.3",
    "cordova-android": "8.0.0",
    "cordova-plugin-speechrecognition": "1.2.0",
    "ionic-angular": "3.9.2",
    "ionicons": "3.0.0",
    "rxjs": "^6.0.0",
    "rxjs-compat": "^6.5.2",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.18"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.1.0",
    "@ionic/cli-plugin-cordova": "1.6.2",
    "@ionic/cli-plugin-ionic-angular": "1.4.1",
    "cordova-plugin-device": "^1.1.4",
    "cordova-plugin-ionic-webview": "^1.2.1",
    "cordova-plugin-splashscreen": "^4.0.3",
    "cordova-plugin-whitelist": "^1.3.1",
    "ionic-plugin-keyboard": "^2.2.1",
    "typescript": "2.4.2"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-speechrecognition": {},
      "ionic-plugin-keyboard": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {}
    },
    "platforms": [
      "android"
    ]
  }
}

package.json

到目前为止,我一直找不到能够帮助我的答案。我相信这可能是版本兼容性问题。

0 个答案:

没有答案