【发布时间】:2021-05-02 00:50:49
【问题描述】:
import { Component, OnInit, Inject } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { DOCUMENT } from '@angular/common';
import { Router, ActivatedRoute, Params } from '@angular/router';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { NgbModalConfig, NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { AppsService } from '../services/apps.service';
import { IApps, Apps, IDataUser, DataUser, IClient, Client, IAppData, AppData } from '../models/apps.model';
import { NgxSpinnerService } from 'ngx-spinner';
declare var require: any;
@Component({
selector: 'rss-channel-content',
templateUrl: './rss-channel.component.html',
styleUrls: ['./rss-channel.component.scss'],
providers: [
AppsService,
NgbModalConfig,
NgbModal
]
})
export class RssChannelComponent implements OnInit {
public isGallery: boolean = false;
public is_view: boolean = false;
public is_save: boolean = false;
private id_app: string;
public structure_app: IApps = new Apps();
public form_data_user: FormGroup;
public href: string = '';
public url: string = '';
public ocultar: boolean = false;
public feed = require('rss-to-json');
public rss: any;
constructor(
private appsService: AppsService,
private route: ActivatedRoute,
private modalService: NgbModal,
private router: Router,
private spinner: NgxSpinnerService,
private titleService: Title,
@Inject(DOCUMENT) private _document: HTMLDocument
) { }
ngOnInit() {
this.spinner.show();
this.id_app = this.route.snapshot.params['id'];
this.getApplication();
this.getUrl();
}
private getUrl() {
this.href = this.router.url;
console.log(this.router.url);
this.url = this.appsService.getUrl(this.href);
console.log('url', this.url);
}
private getApplication() {
this.appsService.getApp(this.id_app).subscribe(async (response) => {
console.log('response', response);
this.structure_app = response.response.options;
this.titleService.setTitle(this.structure_app.name_app);
this._document.getElementById('appFavicon').setAttribute('href', this.structure_app.icono_app);
this.rss = await this.valueRss();
this.is_view = true;
}, (error) => {
console.log(error);
});
}
valueRss() {
return new Promise((resolve, reject) => {
console.log(this.structure_app.rss_url);
this.feed.load(this.structure_app.rss_url, function (err, rss) {
console.log(rss);
resolve(rss);
});
this.spinner.hide();
});
}
/**
* changeColor
*/
public changeColor(col: string, amt: any) {
amt = amt === undefined ? -30 : amt;
col = col === undefined ? '#eee' : col;
return this.appsService.changeColor(col, amt);
}
public open(e: any) {
this.modalService.open(e, { centered: true, size: 'lg' });
}
}
说明:当我调用这个 getApplication api 方法时,在该方法内部,我调用 valueRSS 函数, 但它给 this.feed.load 不是一个函数,也给我过程没有定义 我正在使用 Angular 10 和 rss-to-json 版本 1.0.5。 基本上在那个 api 中我们有 rss url 的响应,所以我们将 rss url 转换为 json 数据并将其显示为 html
【问题讨论】:
-
任何答案都应该得到认可..请帮助我
-
this.feed 是什么?这个属性分配在哪里?您收到错误是因为 this.feed 未定义。你在 undefined 上调用的任何东西都会给你错误。
-
我认为提要被定义为未定义..!!
-
@Alvin Saldanha ,public feed = require('rss-to-json'); feed 是 rss-to-json 库
-
@AlvinSaldanha public feed = require('rss-to-json');它是我从 rss-to-json 库导入的库