gpt4 book ai didi

node.js - Ionic - 运行时错误 : Object(. ..) 不是函数

转载 作者:太空宇宙 更新时间:2023-11-04 01:47:01 26 4
gpt4 key购买 nike

我有一个非常基本的项目:

https://github.com/napolev/ionic-start

这基本上是 Ionic 入门项目:

// https://ionicframework.com/getting-started
$ ionic start ionic-start tabs

我添加了以下两个文件:

/src/extras/social-media.ts

import * as Promise from 'bluebird';
import { User } from './user';

export var LoginPromise = function(service): Promise<string> {
return new Promise((resolve) => {
setTimeout(function(){
resolve('Will Smith');
}, 2000)
});
};

//*/ IF I COMMENT THIS BLOCK OUT, THERE IS NO ERROR
// this function is not used by this project
// but for some specific reasons it is required to be here
// this code is a simplification of a bigger project
export var callMeIfYouNeedMe = function(id) {
return new Promise((resolve) => {
User.findById(id, function(err, user) {
console.log(user);
resolve(user);
});
});
}
// END OF BLOCK */

/src/extras/user.ts

import { Document, Schema, Model, model} from "mongoose";

export interface IUser {
name: string;
}
export interface IUserDocument extends IUser, Document {

}
export var UserSchema: Schema = new Schema({
name: String,
});

export const User: Model<IUserDocument> = model<IUserDocument>("User", UserSchema);

The code right above works properly on a node project (I tried by myself). I got it from: http://brianflove.com/2016/10/04/typescript-declaring-mongoose-schema-model/#schema--model With the last export I create a model of type: IUserDocument.

我还修改了以下两个文件:

/src/pages/home/home.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { LoginPromise } from '../../extras/social-media';

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

constructor(public navCtrl: NavController) {

}

test() {
console.log('Hello World');
LoginPromise('facebook').then(
(name: string) => {
console.log('### Social Media -> ' + name);
}
);
}

}

/src/pages/home/home.html

<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>

<ion-content padding>
<h2>Welcome to Ionic!</h2>
<p>
This starter project comes with simple tabs-based layout for apps
that are going to primarily use a Tabbed UI.
</p>
<p>
Take a look at the <code>src/pages/</code> directory to add or change tabs,
update any existing page or create new pages.
</p>

<button ion-button (click)="test()" color="primary">Test</button>

</ion-content>

我的问题是,当我运行时:

$ ionic serve --no-open

我在控制台上没有收到任何错误,但在浏览器上我收到以下错误:

"Runtime Error: Object(...) is not a function"

正如您在这里看到的:

enter image description here

您知道这里会发生什么以及我如何才能完成这项工作吗?

谢谢!

最佳答案

Runtime Error: Object(…) is not a function

您的电话:

model<IUserDocument>("User", UserSchema);

是错误的。 model 不是一个函数。它是一个对象。

修复

不要调用对象。代码错误。

关于node.js - Ionic - 运行时错误 : Object(. ..) 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51055635/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com