angular - Angular2 中类型 '{}' 上不存在属性

标签 angular typescript

我已经使用 http 调用获取数据。但是,我在编译时显示了以上错误。

user.component.ts

this._user.saveUsers(model).then(data => {
    if(data.success==true){
        this.router.navigate(['/user/list']);
    }else{
        console.log("data")
    }
});

注意:我的对象是动态的。取决于我的 http 调用

错误:

app/users/users.component.ts(33,21):错误 TS2339:属性“success”在类型“{}”上不存在。 app/users/users.component.ts(34,38):错误 TS2339:属性“数据”在类型“{}”上不存在。 app/users/users.component.ts(76,25):错误 TS2339:属性“success”在类型“{}”上不存在。

最佳答案

我不知道第 33 行和第 34 行,因为它们没有显示在您的代码中,但是对于第 76 行,您必须输入

data: any

或者

data: {success: any}

关于angular - Angular2 中类型 '{}' 上不存在属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39709205/

相关文章:

javascript - 在 Typescript/JavaScript 中从平面数组构建树数组

Angular 2 给 SystemJS 找不到/angular2/http 模块

angular 2 - 如何使用模板引用变量获取子组件的 HTMLElement/ElementRef?

reactjs - 在 typescript 中 react 懒惰

typescript - RxJS6:为什么可观察的管道运算符只接收 OperatorFunction 而不是 MonoTypeOperatorFunction

angular - 在使用 Primeng 的 FileUpload 组件上传之前添加自定义 header

javascript - 有没有办法用 Angular 原生国际化机制来翻译绑定(bind)?

angular - 使用 ng-zorro 构建动态菜单

javascript - 无法将 useState 与 typescript 一起使用(找不到名称 'useState' )

Angular @Input 以编程方式为 3rd 方控件设置