Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: SyntaxError: Unexpected strict mode reserved word(…)..

app.template.html

<div class="container">
   <div class="row">
      <div class="col-md-6 ">
         <button class= "btn btn-primary" (click)="onAddMessage()">RANDOM BUTTON</button>
      </div>
   </div>
</div>
<div class="container">
   <div class="row">
      <div class="col-md-6 ">
         <article class="panel panel-default" *ngFor = "let latestmessage of messages" >
            <div class="panel-body">
               {{ latestmessage.content }}
            </div>
         </article>
      </div>
   </div>
</div>

app.component.ts

import { Component } from '@angular/core';
import { Message } from './message.model';

@Component({
    moduleId: module.id,
    selector: 'my-app',
    templateUrl: 'app.template.html'
})
export class AppComponent {
    messages: Message[] = [
        new Message('hello')
    ];

    onAddMessage() {
        const rnd = Math.ceil(Math.random() * 100);
        const msg = new Message(rnd + ' is a awsome number');
        this.messages.push(msg);
    }
}

message.model.ts

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

export class Message(){
    constructor(public content: string){}
}

This code is build in angularjs2 and nodejs .I created a button.when i click on button it give me response like this hello 99 number is an awesome number.what is reserved word in this code?? anyone can help??

like image 887
Sonam Singh Avatar asked Aug 30 '26 04:08

Sonam Singh


2 Answers

I got a similar error when I was using await but the nearest parent function was not async.

like image 113
Mark Jackson Avatar answered Sep 02 '26 18:09

Mark Jackson


The problem is that you are declaring the Message class with parentheses after its name ():

export class Message(){

You may change the message.model.ts to:

message.model.ts

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

export class Message{
    constructor(public content: string){}
}
like image 42
lenilsondc Avatar answered Sep 02 '26 18:09

lenilsondc



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!