Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Define custom property in the same component in angular2

Tags:

angular

I am trying to define a custom property count. But following gives error:Can't bind to 'count' since it isn't a known property of 'p'. How to remove this error and make count a custom property of <p>

other.component.html

<p [count] = "10">
  other works!
</p>

other.component.ts

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

@Component({
  selector: 'app-other',
  templateUrl: './other.component.html',
  styleUrls: ['./other.component.css']
})
export class OtherComponent implements OnInit {

  @Input() count = 10;

  constructor() { }

  ngOnInit() {
  }

}
like image 289
dasfdsa Avatar asked Oct 18 '25 03:10

dasfdsa


1 Answers

<p> doesn't have a name property. You can bind to the name attribute using

[attr.name]="name"

or alternatively

attr.name="{{name}}"

Use this 2nd form (interpolation) only for binding string values, because the passed value will always be stringified.

like image 107
Günter Zöchbauer Avatar answered Oct 19 '25 19:10

Günter Zöchbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!