我在其他帖子中也看到过同样的错误,但它们并不适合我。
我有一个角分量,我需要从url中读取一个queryParam,例如在http://localhost:4200/sample-page?page=3中,我想将数字3存储到一个分量局部变量中。
/**
* Set page by url parameter
*/
export const setPaginationMarkByUrlParam = (activatedRoute): number => {
// Get page param from Url to set pagination page
const page
我有以下spec.ts文件:
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {OnboardingSliderComponent} from './onboarding-slider.component';
import {IconPipe} from "@shared/pipes/icon/icon.pipe"
假设我在我的组件中订阅了route params: this.route.params.subscribe((params) => {
// what the params object holds
// params.id1 params.id2
// what the current route looks like
//localhost/params.id1/params.id2
}); 我如何在Angular中对params.id2进行单元测试?示例:我想测试params.id2是否>0 目前,我已经这样做了: // top of th
我正在尝试创建一个模拟的路由器对象并将其注入到TestBed配置中,但它不起作用。配置如下: let mockQuote: QuoteService = new QuoteService(null, null);
let mockOshcStore: OshcStore = new OshcStore(null);
let mockActivatedRoute: ActivatedRoute = new ActivatedRoute();
let mockRouter: Router = new Router(null, null, null, null, null, null, null,
仅从对应的页面组件获取params.get("id"),不能从其他单独组件(headerComponent)访问params id
//Its worked only correspond component only
this.activatedRoute.paramMap.subscribe( params => {
this.projectName = params.get("id");
console.log( this.projectName );
})
//Tried with these code