1

I can't understand where is a bug here.

add.component.ts:

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

@Component({
    selector: 'counter',
    templateUrl: './add.component.html'
})
export class CounterComponent {
    public currentCount = 0;

    public incrementCounter() {
        this.currentCount++;
    }
}

add.component.html:

<h1>Counter</h1>

<p>This is a simple example of an Angular component.</p>

<p>Current count: <strong>{{ currentCount }}</strong></p>

<button (click)="incrementCounter()">Increment</button>

When I click on the button, nothing happens.

4
  • Create a plunker if possible Commented Aug 7, 2017 at 15:36
  • Are you getting any console errors? This should work as far as I can tell. Commented Aug 7, 2017 at 15:46
  • Works as expected, here is a plunk: plnkr.co/edit/0eGfLSzZjhr9a6vtDhdC Commented Aug 7, 2017 at 15:48
  • Official documentation working sample embed.plnkr.co/?show=preview Commented Aug 7, 2017 at 15:54

1 Answer 1

1

I have tested it in this plunker and it does work as expected. Apparently, something is wrong with your setup. What does the console say? (In your browser, press F12 and check for errors.)

Only difference is I used an inline template:

template: `<h1>Counter</h1>
<p>This is a simple example of an Angular component.</p>
<p>Current count: <strong>{{ currentCount }}</strong></p>
<button (click)="incrementCounter()">Increment</button>`
})
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. The problem was in the wrong sequence of importing modules

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.