linkedin-skill-assessments-quizzes

Angular

问题1. 在这个组件类中,ViewChild 装饰器的作用是什么?

@Component({
    ...
    template: '<p #bio></p>'
})
export class UserDetailsComponent {
    @ViewChild('bio') bio;
}

DigitalOcean - viewchild-access-component

问题2. 在响应式表单中,使用什么方法将 FormControl 连接到原生 DOM input 元素?

Angular.io - Reactive Form Groups

问题3. ActivatedRoute 类上的 paramMapqueryParamMap 有什么区别?

StackOverflow

问题4. 基于以下 async 管道的使用,假设 users 类字段是一个 Observable,对 users Observable 进行了多少次订阅?

<h2>姓名</h2>
<div *ngFor="let user of users | async"></div>
<h2>年龄</h2>
<div *ngFor="let user of users | async"></div>
<h2>性别</h2>
<div *ngFor="let user of users | async"></div>

UltimateCourses

问题5. 如何在 OrderService 的 addOrder 函数中使用 HttpClient 向端点发送 POST 请求?

export class OrderService {
  constructor(private httpClient: HttpClient) {}

  addOrder(order: Order) {
    // 缺少的代码行
  }
}

Angular.io - Sending data to server

问题6. RouterModule.forRoot 方法用于什么?

O’REILLY

问题7. 此组件元数据选择器将匹配哪些 DOM 元素?

@Component({
    selector: 'app-user-card',
    . . .
})

Angular.io - Component Metadata

问题8. 使用内置的 ngFor 结构指令渲染 productNames 列表的正确模板语法是什么?

Angular.io- Structural Directives

问题9. 用于为组件设置 CSS 样式的两个组件装饰器元数据属性是什么?

Angular.io - Component Styles

问题10. 对于以下组件类,您将在模板中使用什么模板语法来显示 title 类字段的值?

@Component({
  selector: 'app-title-card',
  template: '',
})
class TitleCardComponent {
  title = 'User Data';
}

Angular.io - String Interpolation or Text Interpolation

问题11. FormControl 上的 valueChanges 方法的目的是什么?

Angular.io - Displaying a from control value

问题12. 使用什么指令将 <a> 标签链接到路由?

Angular.io - RouterLink

问题13. 在此组件类中,Output 装饰器用于什么?

@Component({
    selector: 'app-shopping-cart',
    . . .
})
export class ShoppingCartComponent {
    @Output() itemTotalChanged = new EventEmitter();
}

Angular.io - Sending data to parent component

问题14. 这两个标记示例在条件处理显示方面有什么区别?

<div *ngIf="isVisible">Active</div>
<div [hidden]="!isVisible">Active</div>

StackOverflow

问题15. 在这个模板驱动表单示例中,当表单有错误时,如何禁用提交按钮?

<form #userForm="ngForm">
  <input type="text" ngModel name="firstName" required />
  <input type="text" ngModel name="lastName" required />
  <button (click)="submit(userForm.value)">Save</button>
</form>

Angular.io - Submit the form with ngSubmit

问题16. 您想查看创建新的 contact-card 组件会生成哪些文件。您会使用哪个命令?

Angular.io - ng generate options

问题17. 基于以下组件,您将使用什么模板语法将 TitleCardComponent 的 titleText 字段绑定到 h1 元素的 title 属性?

@Component({
  selector: 'app-title-card',
  template: '<h1 title="User Data"> </h1>',
})
export class TitleCardComponent {
  titleText = 'User Data';
}

Angular.io - String Interpolation

问题18. 什么是 Angular 生命周期钩子?

Angular.io - Lifecycle hooks

问题19. 为此模板语法代码选择最佳描述:

<span>Boss:  </span>

StackOverflow

问题20. 您如何配置支持 URL 路径 user/23(其中 23 表示请求用户的 id)的 UserDetailComponent 的路由定义?

CodeCraft - Parameterised Routes

问题21. 此指令中的 HostListener 装饰器和 HostBinding 装饰器在做什么?

@Directive({
  selector: '[appCallout]',
})
export class CalloutDirective {
  @HostBinding('style.font-weight') fontWeight = 'normal';

  @HostListener('mouseenter')
  onMouseEnter() {
    this.fontWeight = 'bold';
  }

  @HostListener('mouseleave')
  onMouseLeave() {
    this.fontWeight = 'normal';
  }
}

DigitalOcean

问题22. 在此模板驱动表单字段上,您可以使用什么 Angular 模板语法来访问字段值并在模板标记中检查验证?

<input type="text" ngModel name="firstName" required minlength="4" />
<span *ngIf="">Invalid field data</span>
  1. Angular.io -Show and hide validation error
  2. Medium

问题23. 在此标记中,headerText 模板引用变量将存储什么值类型?

<h1 #headerText>User List</h1>

Pluralsight - Template reference variable

问题24. 基于这两个提供者配置,结果代码逻辑有什么区别(如果有的话)?

[{ provide: FormattedLogger, useClass: Logger }][{ provide: FormattedLogger, useExisting: Logger }];
  1. Angular.io - Dependency Providers
  2. TektutorialHub

问题25. 路由配置中的 data 属性(如下例所示)的目的是什么?

   {
       path: 'customers',
       component: CustomerListComponent,
       data: { accountSection: true }
   }
  1. TektutorialsHub
  2. StackOverflow

问题26. 基于此模板语法,内置的 ngIf 结构指令如何更改渲染的 DOM?

@Component({
  selector: 'app-product',
  template: '<div *ngIf="product"></div>',
})
export class ProductComponent {
  @Input() product;
}

Reference (angular.io)

问题27. 这段代码完成了什么?

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  bootstrap: [AppComponent],
})
export class AppModule {}

platformBrowserDynamic().bootstrapModule(AppModule);

Angular.io - The basic NgModule

问题28. 在此路由配置中,resolve 属性的作用是什么?

{
   path: ':id',
   component: UserComponent,
   resolve: {
     user: UserResolverService
   }
}

angular.io

问题29. 在此组件类中,ContentChildren 装饰器的目的是什么?

@Component({
 . . .
 template: '<ng-content></ng-content>'
})
export class TabsListComponent {
 @ContentChildren(TabComponent) tabs;
}

betterprogramming.pub

问题30. 为了让 Angular 处理应用程序中的组件,组件类型需要在哪里注册?

angular.io

问题31. 在此单元测试中,fixture.detectChanges() 调用的目的是什么?

TestBed.configureTestingModule({
  declarations: [UserCardComponent],
});
let fixture = TestBed.createComponent(UserCardComponent);

fixture.detectChanges();

expect(fixture.nativeElement.querySelector('h1').textContent).toContain(
  fixture.componentInstance.title,
);

angular.io

问题32. 当 goToUser 传递值 15 时,基于以下对 Router.navigate 方法的调用,URL 段将是什么样子?

export class ToolsComponent {
  constructor(private router: Router) {}
  goToUser(id: number) {
    this.router.navigate(['user', id]);
  }
}

angular.io

问题33. 当为 root 提供服务并且还将其添加到延迟加载模块的提供者配置时,注入器向延迟加载模块中的构造函数提供该服务的什么实例?

问题34. 此指令中的 HostBinding 装饰器在做什么?

@Directive({
  selector: ' [appHighlight] ',
})
export class HighlightDirective {
  @HostBinding('class.highlighted') highlight = true;
}

StackOverflow

问题35. 在响应式表单中,在原生 DOM <form> 元素上使用什么 Angular 表单类类型来连接它?

问题36. 假设 username FormControl 已配置了 minLength 验证器,您如何在以下响应式表单标记中为 username 字段设置错误显示?

<form [formGroup]="form">
  <input type="text" formControlName="username" />
  ...
</form>

Codecraft

问题37. 仿真视图封装模式如何处理组件的 CSS?

Angular.io

问题38. 使用以下 TestBed 设置,可以使用什么来访问 UserCardComponent 的渲染 DOM?

TestBed.configureTestingModule({
  declarations: [UserCardComponent],
});
let fixture = TestBed.createComponent(UserCardComponent);
  1. StackOverflow
  2. Angular.io

问题39. 给定这两个组件,基于标记用法,将向 DOM 渲染什么?

@Component({
 selector: 'app-card',
 template: '<h1>Data Card</h1><ng-content></ng-content>'
})
export class CardComponent { }

@Component({
 selector: 'app-bio',
 template: '<ng-content></ng-content>.
})
export class BioComponent { }

// 标记用法:
<app-card><app-bio>Been around for four years.</app-bio></app-card>

问题40. 给定下面代码中的 app-title-card 组件,app-user-card 组件将渲染什么 DOM?

@Component({
   selector: 'app-user-card',
   template: '<app-title-card></app-title-card><p>Jenny Smith</p>'
})

@Component({
   selector: 'app-title-card',
   template: '<h1>User Data</hl>'
})

// 在父组件 html 中使用 user card 组件
<app-user-card></app-user-card>

问题41. 为 @Inject() 装饰器正在寻找的自定义提供者注册选择匹配的代码:

constructor(@Inject('Logger') private logger) { }
  1. StackOverflow
  2. TektutorialHub
  3. Angular.io - Dependency Injection In Action

问题42. 在 getsettings 类方法中,以下 HttpClient.get 方法的使用描述最准确的是哪个?

export class SettingsService {
    constructor(private httpClient: HttpClient) { }
    ...

getSettings()
{
    return this.httpClient.get<Settings>(this.settingsUrl)
        .pipe(
            retry(3)
        );
}}
  1. learnrxjs.io
  2. dev.to

问题43. 当服务需要通过方法进行一些设置以初始化其默认状态时,如何确保在服务被注入到任何地方之前调用该方法?

  1. Angular.io
  2. Stackoverflow

问题44. 哪个语句最能描述 TestBed 的这种用法?

const spy = jasmine.createSpyObj('DataService', ['getUsersFromApi']);
TestBed.configureTestingModule({
  providers: [UserService, { provide: DataService, useValue: spy }],
});
const userService = TestBed.get(UserService);

所有其他测试都将被忽略,包括针对这些提供者之一和未定义提供者进行断言的测试。 尽管在单个测试中针对此配置中的多个提供者进行断言时它会起作用。

问题45. 组件和指令之间的主要区别是什么?

StackOverflow

问题46. 您可以向此指令类添加什么以允许在标记中使用指令时设置截断长度?

@Directive({
    selector: '[appTruncate]'
})
export class TruncateDirective {
    . . .
}

// 期望用法示例:
<p [appTruncate]="10">Some very long text here</p>
  1. Angular.io
  2. StackOverflow

问题47. 如何将查询参数传递给此 HttpClient.get 请求?

export class OrderService {
  constructor(private httpClient: HttpClient) {}

  getOrdersByYear(year: number): Observable<Order[]> {
    return this.httpClient.get<Order[]>(this.ordersUrl);
  }
}
  1. StackOverflow
  2. TektutorialHub

问题48. 假设 DataService 已在应用程序的提供者中注册,基于此组件的构造函数,哪个答案最能描述会发生什么?

@Component({
    ...
})
export class OrderHistoryComponent {
    constructor(private dataService: DataService) {}
    ...
}
  1. StackOverflow
  2. Angular.io - Dependency Injection

问题49. 使用 ngIf 指令完成此标记以实现 else 情况,该情况将显示文本”User is not active”:

<div *ngIf="userIsActive; else inactive">Currently active!</div>

Angular.io

问题50. 延迟加载功能模块的路由定义的正确语法是什么?

Angular.io - Lazy Loading Modules

问题51. 描述此响应式表单示例中如何设置和配置验证:

export class UserFormControl implements OnInit {
    ...
    ngOnInit() {
        this.form = this.formBuilder.group({
            username: this.formBuilder.control('',
                [Validators.required, Validators.minLength(5), this.unique]),
        )};
    }
    unique(control: FormControl) {
        return control.value !== 'admin' ? null: {notUnique: true};
    }
}
  1. Angular.io - Form Validation
  2. Angular University Blog

问题52. Injectable 装饰器在此服务类上做什么?

@Injectable({
    providedIn: 'root'
)}
export class DataService { }

Angular.io

问题53. 描述此代码的用法

export interface AppSettings {
  title: string;
  version: number;
}
export const APP_SETTINGS = new InjectionToken<AppSettings>('app.settings');

问题54. 对于以下模板驱动表单示例,可以将什么参数传递给点击事件中的 submit 方法以提交表单数据?

<form #form="ngForm">
  <input type="text" ngModel="firstName" /> <input type="text" ngModel="lastName" />
  <button (click)="submit()">Save</button>
</form>

问题55. 此路由器代码中 prelodingStrategy 属性配置的目的是什么?

RouterModule.forRoot(
  ...{
    preloadingStrategy: PreloadAllModules,
  },
);

参考:

问题56. 编写此标记以将类字段 userName 的值绑定到 h1 元素 title 属性的替代方法是什么?

<h1 [title]="userName">Current user is </h1>

问题57. 在此示例中,async 管道在做什么?

@Component({
  selector: 'app-users',
  template: '<div *ngFor="let user of users | async"></div>',
})
export class UsersComponent implements OnInit {
  users;
  constructor(private httpClient: HttpClient) {}
  ngOnInit(): void {
    this.users = this.httpClient.get<{ name: string }>('users');
  }
}

问题58. 基于其选择器值,您将如何在标记中使用此指令

@Directive({  selector: '[appTruncate]'
})
export class TruncateDirective{  . . .
}

问题59. 可以在组件上使用什么生命周期钩子来监视该组件上所有 @Input 值的所有更改?

How to detect when an @Input() value changes in Angular?

问题60. 此自定义管道的模板语法用法示例是什么?

@Pipe({ name: 'truncate' })
export class TruncatePipe implements PipeTransform {
  transform(value: string, maxLength: number, showEllipsis: boolean) {
    const newValue = maxLength ? value.substr(0, maxLength) : value;
    return showEllipsis ? '${newValue}...' : newValue;
  }
}

[How do I call an Angular 2 pipe with multiple arguments?] (https://stackoverflow.com/questions/36816788/how-do-i-call-an-angular-2-pipe-with-multiple-arguments)

问题61. 您将运行哪个 Angular CLI 命令来生成 UsersComponent 并将其添加到 SharedModule(在应用程序的 shared.module.ts 文件中)?

问题62. 如何重写此标记,以便在最终 DOM 渲染中不需要 div 容器

<div *ngIf="location">
  <h1></h1>
  <p></p>
</div>

问题63. 如何使用模板语法将名为 tabWidth 的组件类字段绑定到此元素上的内联样式 width CSS 属性?

问题64. 对没有构造函数依赖项的服务进行单元测试需要哪些 Angular 实用程序(如果有)?

Angular unit tests - 重新检查答案

问题65. CanActivate 和 CanLoad 路由守卫之间有什么区别?

CanActivate vs Canload CanActivate 阻止访问路由,CanLoad 阻止延迟加载。

问题66. 在此路由器定义对象中,outlet 属性用于什么?

{  path: 'document',  component: DocumentComponent,  outlet: 'document-box'
}

Angular-outlet - 重新检查答案

问题67. 在此模板语法中,每次更改 items 属性(添加、删除等)时,ngFor 结构指令都会为循环中的所有 DOM 元素重新运行其逻辑。可以使用什么语法使其更高效?

<div *ngFor="let item of items"> - </div>

StackOverflow - How to use trackBy with ngFor

问题68. 此 Angular CLI 命令做什么?

ng build --configuration=production --progress=false

Angular documentation - ng build

问题69. 服务类可以通过哪些装饰器注册为提供者?

问题70. 在此组件类中,Input 装饰器用于什么?

@Component({  selector:'app-product-name',  ...
})
export class ProductNameComponent {  @Input() productName: string
}

问题71. 哪个路由守卫可用于调解导航到路由?

问题72. 如何配置注入器使用现有对象作为令牌,而不是让它实例化类实例?

Configuring dependency providers

问题73. 基于此路由定义,可以将什么注入到 UserDetailComponent 构造函数中以获取 id 路由参数?

{path: 'user/:id', component: UserDetailComponent }

Common Routing Tasks

问题74. 使用以下响应式表单标记,您将添加什么来连接对 onSubmit 类方法的调用?

<form [formGroup]="form">
  <input type="text" formControlName="username" />
  <button type="submit" [disabled]="form. invalid">Submit</button>
</form>

Angular - Forms

问题75. 当 isActive 为 true 时,ngClass 属性指令的这种用法的预期 DOM 代码是什么?

<div [ngClass]="{ 'active-item': isActive }">Item One</div>

Angular - NgClass

问题76. 哪个答案最能解释此模板代码中 ngModel 的用法?

<input [(ngModel)]="user.name" />

Angular - NgModel

问题77. NgModules 可以包含在其他 NgModules 中。您应该使用哪个代码示例在 SharedModule 中包含 TableModule?

text

text

text

问题78. 可以使用什么其他模板语法(替换 ngClass 指令)在此标记中添加或删除 CSS 类名?

<span [ngClass]="{ 'active': isActive, 'can-toggle': canToggle }"> Employed </span>

问题79. 在此指令装饰器示例中,提供者对象字面量中的 multi 属性的目的是什么?

@Directive({
  selector: '[customValidator]',
  providers: [
    {
      provide: NG_VALIDATORS,
      useExisting: CustomValidatorDirective,
      multi: true,
    },
  ],
})
export class CustomValidatorDirective implements Validator {}

StackOverflow

问题80. 您将使用哪个 Angular CLI 命令来运行单元测试,该过程会在文件更改时重新运行测试套件?

问题81. ngOnDestory 生命周期钩子最常见的用途是什么?

问题82. 利用什么 NgModule 装饰器元数据属性来允许其他….?

问题83. 使用以下组件类,您将在模板中使用什么模板语法来显示调用 currentYear 类函数的结果?

@Component({
  selector: 'app-date-card',
  template: '',
})
export class DateCardComponent {
  currentYear() {
    return new Date().getFullYear();
  }
}