如何检查控制台以查看我是否实际将id存储在域数组中?如果我尝试将console.log放在函数之外,则不会出现任何内容。我只是不确定我是否拯救他们。
我想用此完成的是使用该数组的值并使用@input装饰器将它们传递给我的子组件。
import {
Component,
OnInit,
Input
} from '@angular/core';
import {
Router,
ActivatedRoute,
ParamMap
} from '@angular/router';
import {
Location
} from '@angular/common';
import {
ImageService
} from './shared/image.service';
import {
DomainService
} from '../domain.service';
import {
GraphService
} from '../graph.service';
import {
LibraryService
} from '../library.service';
import {
Domain
} from '../library';
import {
Library
} from '../library';
import {
map,
mergeMap
} from 'rxjs/operators';
@Component({
selector: 'app-metric-details',
templateUrl: './metric-details.component.html',
styleUrls: ['./metric-details.component.css']
})
export class MetricDetailsComponent implements OnInit {
visibleImages: any[] = [];
activeId = 0;
domain: Domain[];
constructor(private imageService: ImageService, private domainService: DomainService, private libraryService: LibraryService, private graphService: GraphService, private location: Location, private route: ActivatedRoute, private router: Router) {
this.visibleImages = this.imageService.getImages();
}
ngOnInit() {
this.route.params.subscribe(params => {
{
this.activeId = +params['id'];
console.log(this.activeId) //log the entire params object
// console.log(params['id']) //log the value of id
// const id = +this.route.snapshot.paramMap.get('id');
// console.log(id);
console.log(this.domainService.getDomain(this.activeId));
this.domainService.getDomain(this.activeId).subscribe(domain => this.domain = domain)
console.log("YOOO", this.domain)
}
}
}
答案 0 :(得分:0)
试试这个,你遗漏了一些代币:
import {
Component,
OnInit,
Input
} from '@angular/core';
import {
Router,
ActivatedRoute,
ParamMap
} from '@angular/router';
import {
Location
} from '@angular/common';
import {
ImageService
} from './shared/image.service';
import {
DomainService
} from '../domain.service';
import {
GraphService
} from '../graph.service';
import {
LibraryService
} from '../library.service';
import {
Domain
} from '../library';
import {
Library
} from '../library';
import {
map,
mergeMap
} from 'rxjs/operators';
@Component({
selector: 'app-metric-details',
templateUrl: './metric-details.component.html',
styleUrls: ['./metric-details.component.css']
})
export class MetricDetailsComponent implements OnInit {
visibleImages: any[] = [];
activeId = 0;
domain: Domain[];
constructor(private imageService: ImageService, private domainService:
DomainService,
private libraryService: LibraryService, private graphService:
GraphService,
private location: Location, private route: ActivatedRoute, private
router: Router) {
this.visibleImages = this.imageService.getImages();
}
ngOnInit() {
this.route.params.subscribe(params => {
{
this.activeId = +params['id'];
console.log(this.activeId); // log the entire params object
// console.log(params['id']) //log the value of id
// const id = +this.route.snapshot.paramMap.get('id');
// console.log(id);
console.log(this.domainService.getDomain(this.activeId));
this.domainService.getDomain(this.activeId).subscribe(domain => this.domain = domain);
console.log('YOOO', this.domain);
}
});
}}