0

I have written a simple angular application to learn @input to communicate between components but the value is not being passed. I have also read some forums who have faced similar problems but none of the solutions prescribed are working for me. Please guide.

app.componenent.html

<app-task [prioirty]="'p1'"></app-task>

task.component.ts

import { Component, OnInit, Input } from '@angular/core';
import { Task } from 'src/app/task/task';
import { TaskService } from 'src/app/task/services/task.service';
import {AppComponent} from 'src/app/app.component'

@Component({
  selector: 'app-task',
  templateUrl: './task.component.html',
  styleUrls: ['./task.component.css'],
})
export class TaskComponent implements OnInit {     
  constructor(private taskService: TaskService) {        
  }      
  task: Task = new Task();
  @Input() priortiy: string; 
  ngOnInit() {
  }
  addTask(){
    alert(this.priortiy);
    this.taskService.addTask(this.task).subscribe((data : Task) => {}, error => console.error(error),() => console.log("Job Added successfully"));    
  }    
}

When I am trying to display the value of priority in an alert box, I get the value as undefined.

Let me know if anyone wants me to place the complete code.

3
  • 2
    i think it's typo problem : prioirty vs priortiy Commented Jul 15, 2018 at 7:20
  • My bad @Sajeetharan, the timing of the answer was closed hence the mistake Commented Jul 15, 2018 at 8:20
  • LOL even the answers have the wrong spelling. Perhaps this might be useful Code Spell Checker Commented Jul 15, 2018 at 20:25

1 Answer 1

3

You have a typo,

Change from

 @Input() priortiy: string; 

To

 @Input() prioirty: string; 

and alert too,

alert(this.prioirty);
Sign up to request clarification or add additional context in comments.

Comments

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.