Angular - type 'string' is not assignable to type 'boolean' - Solved

By Hardik Savani October 20, 2023 Category : Angular

This post will give you example of type 'string' is not assignable to type 'boolean' angular. you will learn angular type 'string' is not assignable to type 'boolean'. I would like to share with you angular template type 'string' is not assignable to type 'boolean'. you will learn angular directive type 'string' is not assignable to type 'boolean'.

Few days ago i was working on angular pagination i need to assign "true" and "false" boolean value to tag attribute. i simply assign "true" and "false" to that attribute as like bellow:

....

<pagination-controls (pageChange)="pageChangeEvent($event)" previousLabel="Prev"

nextLabel="Next"

responsive="true"

></pagination-controls>

But i found following error:

"type 'string' is not assignable to type 'boolean'." so i must need to assign data type to that string. so i created variable on component and then i used it.

so let's see bellow solution:

Component Code:

import { Component, OnInit } from '@angular/core';

import { UsersService } from './services/users.service';

@Component({

selector: 'app-root',

templateUrl: './app.component.html',

styleUrls: ['./app.component.css']

})

export class AppComponent implements OnInit {

users:any;

p: number = 1;

total: number = 0;

zero: number = 0;

responsiveP: boolean = true;

......

View Code:

<pagination-controls (pageChange)="pageChangeEvent($event)" previousLabel="Prev"

nextLabel="Next"

(responsive)="responsiveP"

></pagination-controls>

then it works.

I hope it can help you...

Tags :
Shares