• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

214
Views
Property 'bordered' does not exist on type 'Object'

Relevant TypeScript code:

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

@Component({
  selector: 'app-ng-class-example',
  templateUrl: './ng-class-example.component.html'
})
export class NgClassExampleComponent implements OnInit {
  isBordered: boolean;
  classesObj: Object;
  classList: string[];

  constructor() { } 

  ngOnInit(): void { 
    this.isBordered = true;
    this.classList = ['blue', 'round']
    this.toggleBorder();
  }

  toggleBorder(): void {
    this.isBordered = !this.isBordered;
    this.classesObj = {
      bordered: this.isBordered
    };
  }
}

Corresponding template (the relevant part).

<div [ngClass]="classesObj">
  Using object var. Border {{ classesObj.bordered ? "ON" : "OFF" }}
</div>

Now I get an error in my .html file (around the attribute .bordered) stating that: "Property 'bordered' does not exist on type 'Object'".

I am new to TypeScript (and also JavaScript) but it seems to me that 'bordered' is defined on the object, so what is going on?

Thank you in advance!

about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can't just use classesObj: Object in TypeScript because it is assumed to be empty object {}. You need to use any like

classesObj: any;

Or if you want to be specific

classesObj: {
    bordered: boolean
};
about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error