Angular 5 - Why is my input property undefined?Angular HTML bindingAngular EXCEPTION: No provider for Http@Input property is undefined in angular 2's onInitAngular exception: Can't bind to 'ngForIn' since it isn't a known native propertyWhat is the equivalent of ngShow and ngHide in Angular 2+?Angular/RxJs When should I unsubscribe from `Subscription`How to detect when an @Input() value changes in Angular?Huge number of files generated for every Angular projectCan't bind to 'ngModel' since it isn't a known property of 'input'Error TypeError: Cannot read property 'fromDate' of undefined
How are aircraft depainted?
Make 2019 with single digits
Bit one of the Intel 8080's Flags register
How are unbalanced coaxial cables used for broadcasting TV signals without any problems?
How to stabilise the bicycle seatpost and saddle when it is all the way up?
Where to disclose a zero day vulnerability
How do EVA suits manage water excretion?
Why is the T-1000 humanoid?
Were Roman public roads build by private companies?
POSIX compatible way to get user name associated with a user ID
What is and what isn't ullage in rocket science?
How would you control supersoldiers in a late iron-age society?
What hard drive connector is this?
Telling my mother that I have anorexia without panicking her
How major are these paintwork & rust problems?
why car dealer is insisting on loan v/s cash
What's 待ってるから mean?
Which is the current decimal separator?
3d printed bricks quality?
What was the ultimate objective of The Party in 1984?
Will the UK home office know about 5 previous visa rejections in other countries?
Diffraction of a wave passing through double slits
Bash, import output from command as command
I asked for a graduate student position from a professor. He replied "welcome". What does that mean?
Angular 5 - Why is my input property undefined?
Angular HTML bindingAngular EXCEPTION: No provider for Http@Input property is undefined in angular 2's onInitAngular exception: Can't bind to 'ngForIn' since it isn't a known native propertyWhat is the equivalent of ngShow and ngHide in Angular 2+?Angular/RxJs When should I unsubscribe from `Subscription`How to detect when an @Input() value changes in Angular?Huge number of files generated for every Angular projectCan't bind to 'ngModel' since it isn't a known property of 'input'Error TypeError: Cannot read property 'fromDate' of undefined
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm new to Angular5 and searched for hours but couldn't resolve my issue.
Every related threads on SO are not in the same version as me.
I have an input on which I want to trigger a function when something is typed in that input.
Here's my input:
<input
#autocompleteInput
class="inputHeader"
(click)="openSearch()"
placeholder="Coupe homme, lissage brésilen, ..."
/>
Here's my input property declaration:
@Input() autocompleteInput: string;
When I console.log(this.autocompleteInput);
in the ngOnInit() method, it display "undefined".
What am I doing wrong ?
Any help would be welcomed.
angular
add a comment
|
I'm new to Angular5 and searched for hours but couldn't resolve my issue.
Every related threads on SO are not in the same version as me.
I have an input on which I want to trigger a function when something is typed in that input.
Here's my input:
<input
#autocompleteInput
class="inputHeader"
(click)="openSearch()"
placeholder="Coupe homme, lissage brésilen, ..."
/>
Here's my input property declaration:
@Input() autocompleteInput: string;
When I console.log(this.autocompleteInput);
in the ngOnInit() method, it display "undefined".
What am I doing wrong ?
Any help would be welcomed.
angular
There is not an initialization in this example.
– JoseJimRin
Mar 28 at 9:13
2
You should use @ViewChild if you want to get reference to the input field.
– iamjc015
Mar 28 at 9:15
@iamjc015 you're right, now I get the input. But the main problem is that the input event is not triggered when i type on the input.
– Pierrick Martellière
Mar 28 at 9:24
add a comment
|
I'm new to Angular5 and searched for hours but couldn't resolve my issue.
Every related threads on SO are not in the same version as me.
I have an input on which I want to trigger a function when something is typed in that input.
Here's my input:
<input
#autocompleteInput
class="inputHeader"
(click)="openSearch()"
placeholder="Coupe homme, lissage brésilen, ..."
/>
Here's my input property declaration:
@Input() autocompleteInput: string;
When I console.log(this.autocompleteInput);
in the ngOnInit() method, it display "undefined".
What am I doing wrong ?
Any help would be welcomed.
angular
I'm new to Angular5 and searched for hours but couldn't resolve my issue.
Every related threads on SO are not in the same version as me.
I have an input on which I want to trigger a function when something is typed in that input.
Here's my input:
<input
#autocompleteInput
class="inputHeader"
(click)="openSearch()"
placeholder="Coupe homme, lissage brésilen, ..."
/>
Here's my input property declaration:
@Input() autocompleteInput: string;
When I console.log(this.autocompleteInput);
in the ngOnInit() method, it display "undefined".
What am I doing wrong ?
Any help would be welcomed.
angular
angular
edited Mar 28 at 10:27
StefanK
125 bronze badges
125 bronze badges
asked Mar 28 at 9:11
Pierrick MartellièrePierrick Martellière
5159 silver badges30 bronze badges
5159 silver badges30 bronze badges
There is not an initialization in this example.
– JoseJimRin
Mar 28 at 9:13
2
You should use @ViewChild if you want to get reference to the input field.
– iamjc015
Mar 28 at 9:15
@iamjc015 you're right, now I get the input. But the main problem is that the input event is not triggered when i type on the input.
– Pierrick Martellière
Mar 28 at 9:24
add a comment
|
There is not an initialization in this example.
– JoseJimRin
Mar 28 at 9:13
2
You should use @ViewChild if you want to get reference to the input field.
– iamjc015
Mar 28 at 9:15
@iamjc015 you're right, now I get the input. But the main problem is that the input event is not triggered when i type on the input.
– Pierrick Martellière
Mar 28 at 9:24
There is not an initialization in this example.
– JoseJimRin
Mar 28 at 9:13
There is not an initialization in this example.
– JoseJimRin
Mar 28 at 9:13
2
2
You should use @ViewChild if you want to get reference to the input field.
– iamjc015
Mar 28 at 9:15
You should use @ViewChild if you want to get reference to the input field.
– iamjc015
Mar 28 at 9:15
@iamjc015 you're right, now I get the input. But the main problem is that the input event is not triggered when i type on the input.
– Pierrick Martellière
Mar 28 at 9:24
@iamjc015 you're right, now I get the input. But the main problem is that the input event is not triggered when i type on the input.
– Pierrick Martellière
Mar 28 at 9:24
add a comment
|
5 Answers
5
active
oldest
votes
Input property is used for component interaction. Here if you want to get the value you entered in input, then you can use
in html:
<input
#autocompleteInput
class="inputHeader"
(click)="openSearch()"
placeholder="Coupe homme, lissage brésilen, ..."
(input)="inputData($event.target.value)"
/>
in ts:
inputData(data: any)
console.log(data)
Already tried it, input, keyup, or change events are never triggering.
– Pierrick Martellière
Mar 28 at 9:25
did any of the other answers work?
– Seba Cherian
Mar 28 at 9:25
Nope :/ Already tried a lot of SO answers
– Pierrick Martellière
Mar 28 at 9:26
Can you try my updated answer? It worked for me
– Seba Cherian
Mar 28 at 9:32
Already tried it from @jo_va's answer
– Pierrick Martellière
Mar 28 at 9:33
|
show 1 more comment
You should use "keyup" event for the same:
<input
#autocompleteInput
class="inputHeader"
(click)="openSearch()"
placeholder="Coupe homme, lissage brésilen, ..."
(keyup)="methodName($event)"
/>
Hi, thanks for your answer but that's not working :/
– Pierrick Martellière
Mar 28 at 9:18
can you share your code with stackblitz.com so that I can have better understanding?
– Sumit Vekariya
Mar 28 at 9:22
stackblitz.com/edit/angular-suqctf
– Pierrick Martellière
Mar 28 at 9:30
add a comment
|
In ts file
import ViewChild from '@angular/core';
export class tsClass implements OnInit
@ViewChild('autocompleteInput') autocompleteInput;
//now you can user it
this.autocompleteInput = this.autocompleteInput.nativeElement;
Right, thanks, but the main problem is that (input), (change) or (keyup) events are not triggered :/
– Pierrick Martellière
Mar 28 at 9:32
One question only if not solved yet, you want input because html is in different component right?
– Pratik
Mar 29 at 6:02
add a comment
|
autocompleteInput
is a reference to your input
element, and not the content of your input.
You would have to use it with the ViewChild
decorator to get an ElementRef
:
@ViewChild('autocompleteInput') inputRef: ElementRef;
From this ElementRef
, you can get the native element (HTMLInputElement) with inputRef.nativeElement
.
However, if you want to get the text as it is typed in the input, you should use the input
event:
<input
#autocompleteInput
type="text"
class="inputHeader"
(input)="onInput($event.target.value)"
placeholder="Coupe homme, lissage brésilen, ..."
/>
onInput(value: string)
// do something with value
Or use an ngModel
to control the value of your input:
<input
#autocompleteInput
type="text"
class="inputHeader"
[ngModel]="value"
(ngModelChange)="valueChanged($event)"
placeholder="Coupe homme, lissage brésilen, ..."
/>
value: string;
valueChanged(value: string)
this.value = value;
// do something with this.value
See this Stackblitz demo
If you are using Ionic, you should use <ion-input>
instead of <input>
:
<ion-input type="text" (input)="onInput($event.target.value)"></ion-input>
You're absolutely right, I already went trying this soution, but the problem is that the input event is never triggered. Do you know what could cause this please ?
– Pierrick Martellière
Mar 28 at 9:23
This is a strange issue, could share your code via a stackblitz ?
– jo_va
Mar 28 at 9:25
For sure, wait plz
– Pierrick Martellière
Mar 28 at 9:26
@Pierrick Martellière, I provided a short stackblitz demo to my answer
– jo_va
Mar 28 at 9:29
1
@Pierrick Martellière, no problem!
– jo_va
Mar 28 at 9:53
|
show 12 more comments
Turns out there was another input in the bottom of my template that was used when the first input was clicked. The input event now triggers well.
Sorry for my stupidity and thanks to everyone for the time and patience.
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55393810%2fangular-5-why-is-my-input-property-undefined%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Input property is used for component interaction. Here if you want to get the value you entered in input, then you can use
in html:
<input
#autocompleteInput
class="inputHeader"
(click)="openSearch()"
placeholder="Coupe homme, lissage brésilen, ..."
(input)="inputData($event.target.value)"
/>
in ts:
inputData(data: any)
console.log(data)
Already tried it, input, keyup, or change events are never triggering.
– Pierrick Martellière
Mar 28 at 9:25
did any of the other answers work?
– Seba Cherian
Mar 28 at 9:25
Nope :/ Already tried a lot of SO answers
– Pierrick Martellière
Mar 28 at 9:26
Can you try my updated answer? It worked for me
– Seba Cherian
Mar 28 at 9:32
Already tried it from @jo_va's answer
– Pierrick Martellière
Mar 28 at 9:33
|
show 1 more comment
Input property is used for component interaction. Here if you want to get the value you entered in input, then you can use
in html:
<input
#autocompleteInput
class="inputHeader"
(click)="openSearch()"
placeholder="Coupe homme, lissage brésilen, ..."
(input)="inputData($event.target.value)"
/>
in ts:
inputData(data: any)
console.log(data)
Already tried it, input, keyup, or change events are never triggering.
– Pierrick Martellière
Mar 28 at 9:25
did any of the other answers work?
– Seba Cherian
Mar 28 at 9:25
Nope :/ Already tried a lot of SO answers
– Pierrick Martellière
Mar 28 at 9:26
Can you try my updated answer? It worked for me
– Seba Cherian
Mar 28 at 9:32
Already tried it from @jo_va's answer
– Pierrick Martellière
Mar 28 at 9:33
|
show 1 more comment
Input property is used for component interaction. Here if you want to get the value you entered in input, then you can use
in html:
<input
#autocompleteInput
class="inputHeader"
(click)="openSearch()"
placeholder="Coupe homme, lissage brésilen, ..."
(input)="inputData($event.target.value)"
/>
in ts:
inputData(data: any)
console.log(data)
Input property is used for component interaction. Here if you want to get the value you entered in input, then you can use
in html:
<input
#autocompleteInput
class="inputHeader"
(click)="openSearch()"
placeholder="Coupe homme, lissage brésilen, ..."
(input)="inputData($event.target.value)"
/>
in ts:
inputData(data: any)
console.log(data)
edited Mar 28 at 9:32
answered Mar 28 at 9:18
Seba CherianSeba Cherian
1,1981 silver badge14 bronze badges
1,1981 silver badge14 bronze badges
Already tried it, input, keyup, or change events are never triggering.
– Pierrick Martellière
Mar 28 at 9:25
did any of the other answers work?
– Seba Cherian
Mar 28 at 9:25
Nope :/ Already tried a lot of SO answers
– Pierrick Martellière
Mar 28 at 9:26
Can you try my updated answer? It worked for me
– Seba Cherian
Mar 28 at 9:32
Already tried it from @jo_va's answer
– Pierrick Martellière
Mar 28 at 9:33
|
show 1 more comment
Already tried it, input, keyup, or change events are never triggering.
– Pierrick Martellière
Mar 28 at 9:25
did any of the other answers work?
– Seba Cherian
Mar 28 at 9:25
Nope :/ Already tried a lot of SO answers
– Pierrick Martellière
Mar 28 at 9:26
Can you try my updated answer? It worked for me
– Seba Cherian
Mar 28 at 9:32
Already tried it from @jo_va's answer
– Pierrick Martellière
Mar 28 at 9:33
Already tried it, input, keyup, or change events are never triggering.
– Pierrick Martellière
Mar 28 at 9:25
Already tried it, input, keyup, or change events are never triggering.
– Pierrick Martellière
Mar 28 at 9:25
did any of the other answers work?
– Seba Cherian
Mar 28 at 9:25
did any of the other answers work?
– Seba Cherian
Mar 28 at 9:25
Nope :/ Already tried a lot of SO answers
– Pierrick Martellière
Mar 28 at 9:26
Nope :/ Already tried a lot of SO answers
– Pierrick Martellière
Mar 28 at 9:26
Can you try my updated answer? It worked for me
– Seba Cherian
Mar 28 at 9:32
Can you try my updated answer? It worked for me
– Seba Cherian
Mar 28 at 9:32
Already tried it from @jo_va's answer
– Pierrick Martellière
Mar 28 at 9:33
Already tried it from @jo_va's answer
– Pierrick Martellière
Mar 28 at 9:33
|
show 1 more comment
You should use "keyup" event for the same:
<input
#autocompleteInput
class="inputHeader"
(click)="openSearch()"
placeholder="Coupe homme, lissage brésilen, ..."
(keyup)="methodName($event)"
/>
Hi, thanks for your answer but that's not working :/
– Pierrick Martellière
Mar 28 at 9:18
can you share your code with stackblitz.com so that I can have better understanding?
– Sumit Vekariya
Mar 28 at 9:22
stackblitz.com/edit/angular-suqctf
– Pierrick Martellière
Mar 28 at 9:30
add a comment
|
You should use "keyup" event for the same:
<input
#autocompleteInput
class="inputHeader"
(click)="openSearch()"
placeholder="Coupe homme, lissage brésilen, ..."
(keyup)="methodName($event)"
/>
Hi, thanks for your answer but that's not working :/
– Pierrick Martellière
Mar 28 at 9:18
can you share your code with stackblitz.com so that I can have better understanding?
– Sumit Vekariya
Mar 28 at 9:22
stackblitz.com/edit/angular-suqctf
– Pierrick Martellière
Mar 28 at 9:30
add a comment
|
You should use "keyup" event for the same:
<input
#autocompleteInput
class="inputHeader"
(click)="openSearch()"
placeholder="Coupe homme, lissage brésilen, ..."
(keyup)="methodName($event)"
/>
You should use "keyup" event for the same:
<input
#autocompleteInput
class="inputHeader"
(click)="openSearch()"
placeholder="Coupe homme, lissage brésilen, ..."
(keyup)="methodName($event)"
/>
answered Mar 28 at 9:14
Sumit VekariyaSumit Vekariya
1046 bronze badges
1046 bronze badges
Hi, thanks for your answer but that's not working :/
– Pierrick Martellière
Mar 28 at 9:18
can you share your code with stackblitz.com so that I can have better understanding?
– Sumit Vekariya
Mar 28 at 9:22
stackblitz.com/edit/angular-suqctf
– Pierrick Martellière
Mar 28 at 9:30
add a comment
|
Hi, thanks for your answer but that's not working :/
– Pierrick Martellière
Mar 28 at 9:18
can you share your code with stackblitz.com so that I can have better understanding?
– Sumit Vekariya
Mar 28 at 9:22
stackblitz.com/edit/angular-suqctf
– Pierrick Martellière
Mar 28 at 9:30
Hi, thanks for your answer but that's not working :/
– Pierrick Martellière
Mar 28 at 9:18
Hi, thanks for your answer but that's not working :/
– Pierrick Martellière
Mar 28 at 9:18
can you share your code with stackblitz.com so that I can have better understanding?
– Sumit Vekariya
Mar 28 at 9:22
can you share your code with stackblitz.com so that I can have better understanding?
– Sumit Vekariya
Mar 28 at 9:22
stackblitz.com/edit/angular-suqctf
– Pierrick Martellière
Mar 28 at 9:30
stackblitz.com/edit/angular-suqctf
– Pierrick Martellière
Mar 28 at 9:30
add a comment
|
In ts file
import ViewChild from '@angular/core';
export class tsClass implements OnInit
@ViewChild('autocompleteInput') autocompleteInput;
//now you can user it
this.autocompleteInput = this.autocompleteInput.nativeElement;
Right, thanks, but the main problem is that (input), (change) or (keyup) events are not triggered :/
– Pierrick Martellière
Mar 28 at 9:32
One question only if not solved yet, you want input because html is in different component right?
– Pratik
Mar 29 at 6:02
add a comment
|
In ts file
import ViewChild from '@angular/core';
export class tsClass implements OnInit
@ViewChild('autocompleteInput') autocompleteInput;
//now you can user it
this.autocompleteInput = this.autocompleteInput.nativeElement;
Right, thanks, but the main problem is that (input), (change) or (keyup) events are not triggered :/
– Pierrick Martellière
Mar 28 at 9:32
One question only if not solved yet, you want input because html is in different component right?
– Pratik
Mar 29 at 6:02
add a comment
|
In ts file
import ViewChild from '@angular/core';
export class tsClass implements OnInit
@ViewChild('autocompleteInput') autocompleteInput;
//now you can user it
this.autocompleteInput = this.autocompleteInput.nativeElement;
In ts file
import ViewChild from '@angular/core';
export class tsClass implements OnInit
@ViewChild('autocompleteInput') autocompleteInput;
//now you can user it
this.autocompleteInput = this.autocompleteInput.nativeElement;
answered Mar 28 at 9:17
PratikPratik
1,4711 gold badge9 silver badges7 bronze badges
1,4711 gold badge9 silver badges7 bronze badges
Right, thanks, but the main problem is that (input), (change) or (keyup) events are not triggered :/
– Pierrick Martellière
Mar 28 at 9:32
One question only if not solved yet, you want input because html is in different component right?
– Pratik
Mar 29 at 6:02
add a comment
|
Right, thanks, but the main problem is that (input), (change) or (keyup) events are not triggered :/
– Pierrick Martellière
Mar 28 at 9:32
One question only if not solved yet, you want input because html is in different component right?
– Pratik
Mar 29 at 6:02
Right, thanks, but the main problem is that (input), (change) or (keyup) events are not triggered :/
– Pierrick Martellière
Mar 28 at 9:32
Right, thanks, but the main problem is that (input), (change) or (keyup) events are not triggered :/
– Pierrick Martellière
Mar 28 at 9:32
One question only if not solved yet, you want input because html is in different component right?
– Pratik
Mar 29 at 6:02
One question only if not solved yet, you want input because html is in different component right?
– Pratik
Mar 29 at 6:02
add a comment
|
autocompleteInput
is a reference to your input
element, and not the content of your input.
You would have to use it with the ViewChild
decorator to get an ElementRef
:
@ViewChild('autocompleteInput') inputRef: ElementRef;
From this ElementRef
, you can get the native element (HTMLInputElement) with inputRef.nativeElement
.
However, if you want to get the text as it is typed in the input, you should use the input
event:
<input
#autocompleteInput
type="text"
class="inputHeader"
(input)="onInput($event.target.value)"
placeholder="Coupe homme, lissage brésilen, ..."
/>
onInput(value: string)
// do something with value
Or use an ngModel
to control the value of your input:
<input
#autocompleteInput
type="text"
class="inputHeader"
[ngModel]="value"
(ngModelChange)="valueChanged($event)"
placeholder="Coupe homme, lissage brésilen, ..."
/>
value: string;
valueChanged(value: string)
this.value = value;
// do something with this.value
See this Stackblitz demo
If you are using Ionic, you should use <ion-input>
instead of <input>
:
<ion-input type="text" (input)="onInput($event.target.value)"></ion-input>
You're absolutely right, I already went trying this soution, but the problem is that the input event is never triggered. Do you know what could cause this please ?
– Pierrick Martellière
Mar 28 at 9:23
This is a strange issue, could share your code via a stackblitz ?
– jo_va
Mar 28 at 9:25
For sure, wait plz
– Pierrick Martellière
Mar 28 at 9:26
@Pierrick Martellière, I provided a short stackblitz demo to my answer
– jo_va
Mar 28 at 9:29
1
@Pierrick Martellière, no problem!
– jo_va
Mar 28 at 9:53
|
show 12 more comments
autocompleteInput
is a reference to your input
element, and not the content of your input.
You would have to use it with the ViewChild
decorator to get an ElementRef
:
@ViewChild('autocompleteInput') inputRef: ElementRef;
From this ElementRef
, you can get the native element (HTMLInputElement) with inputRef.nativeElement
.
However, if you want to get the text as it is typed in the input, you should use the input
event:
<input
#autocompleteInput
type="text"
class="inputHeader"
(input)="onInput($event.target.value)"
placeholder="Coupe homme, lissage brésilen, ..."
/>
onInput(value: string)
// do something with value
Or use an ngModel
to control the value of your input:
<input
#autocompleteInput
type="text"
class="inputHeader"
[ngModel]="value"
(ngModelChange)="valueChanged($event)"
placeholder="Coupe homme, lissage brésilen, ..."
/>
value: string;
valueChanged(value: string)
this.value = value;
// do something with this.value
See this Stackblitz demo
If you are using Ionic, you should use <ion-input>
instead of <input>
:
<ion-input type="text" (input)="onInput($event.target.value)"></ion-input>
You're absolutely right, I already went trying this soution, but the problem is that the input event is never triggered. Do you know what could cause this please ?
– Pierrick Martellière
Mar 28 at 9:23
This is a strange issue, could share your code via a stackblitz ?
– jo_va
Mar 28 at 9:25
For sure, wait plz
– Pierrick Martellière
Mar 28 at 9:26
@Pierrick Martellière, I provided a short stackblitz demo to my answer
– jo_va
Mar 28 at 9:29
1
@Pierrick Martellière, no problem!
– jo_va
Mar 28 at 9:53
|
show 12 more comments
autocompleteInput
is a reference to your input
element, and not the content of your input.
You would have to use it with the ViewChild
decorator to get an ElementRef
:
@ViewChild('autocompleteInput') inputRef: ElementRef;
From this ElementRef
, you can get the native element (HTMLInputElement) with inputRef.nativeElement
.
However, if you want to get the text as it is typed in the input, you should use the input
event:
<input
#autocompleteInput
type="text"
class="inputHeader"
(input)="onInput($event.target.value)"
placeholder="Coupe homme, lissage brésilen, ..."
/>
onInput(value: string)
// do something with value
Or use an ngModel
to control the value of your input:
<input
#autocompleteInput
type="text"
class="inputHeader"
[ngModel]="value"
(ngModelChange)="valueChanged($event)"
placeholder="Coupe homme, lissage brésilen, ..."
/>
value: string;
valueChanged(value: string)
this.value = value;
// do something with this.value
See this Stackblitz demo
If you are using Ionic, you should use <ion-input>
instead of <input>
:
<ion-input type="text" (input)="onInput($event.target.value)"></ion-input>
autocompleteInput
is a reference to your input
element, and not the content of your input.
You would have to use it with the ViewChild
decorator to get an ElementRef
:
@ViewChild('autocompleteInput') inputRef: ElementRef;
From this ElementRef
, you can get the native element (HTMLInputElement) with inputRef.nativeElement
.
However, if you want to get the text as it is typed in the input, you should use the input
event:
<input
#autocompleteInput
type="text"
class="inputHeader"
(input)="onInput($event.target.value)"
placeholder="Coupe homme, lissage brésilen, ..."
/>
onInput(value: string)
// do something with value
Or use an ngModel
to control the value of your input:
<input
#autocompleteInput
type="text"
class="inputHeader"
[ngModel]="value"
(ngModelChange)="valueChanged($event)"
placeholder="Coupe homme, lissage brésilen, ..."
/>
value: string;
valueChanged(value: string)
this.value = value;
// do something with this.value
See this Stackblitz demo
If you are using Ionic, you should use <ion-input>
instead of <input>
:
<ion-input type="text" (input)="onInput($event.target.value)"></ion-input>
edited Mar 28 at 9:50
answered Mar 28 at 9:17
jo_vajo_va
10.1k3 gold badges10 silver badges32 bronze badges
10.1k3 gold badges10 silver badges32 bronze badges
You're absolutely right, I already went trying this soution, but the problem is that the input event is never triggered. Do you know what could cause this please ?
– Pierrick Martellière
Mar 28 at 9:23
This is a strange issue, could share your code via a stackblitz ?
– jo_va
Mar 28 at 9:25
For sure, wait plz
– Pierrick Martellière
Mar 28 at 9:26
@Pierrick Martellière, I provided a short stackblitz demo to my answer
– jo_va
Mar 28 at 9:29
1
@Pierrick Martellière, no problem!
– jo_va
Mar 28 at 9:53
|
show 12 more comments
You're absolutely right, I already went trying this soution, but the problem is that the input event is never triggered. Do you know what could cause this please ?
– Pierrick Martellière
Mar 28 at 9:23
This is a strange issue, could share your code via a stackblitz ?
– jo_va
Mar 28 at 9:25
For sure, wait plz
– Pierrick Martellière
Mar 28 at 9:26
@Pierrick Martellière, I provided a short stackblitz demo to my answer
– jo_va
Mar 28 at 9:29
1
@Pierrick Martellière, no problem!
– jo_va
Mar 28 at 9:53
You're absolutely right, I already went trying this soution, but the problem is that the input event is never triggered. Do you know what could cause this please ?
– Pierrick Martellière
Mar 28 at 9:23
You're absolutely right, I already went trying this soution, but the problem is that the input event is never triggered. Do you know what could cause this please ?
– Pierrick Martellière
Mar 28 at 9:23
This is a strange issue, could share your code via a stackblitz ?
– jo_va
Mar 28 at 9:25
This is a strange issue, could share your code via a stackblitz ?
– jo_va
Mar 28 at 9:25
For sure, wait plz
– Pierrick Martellière
Mar 28 at 9:26
For sure, wait plz
– Pierrick Martellière
Mar 28 at 9:26
@Pierrick Martellière, I provided a short stackblitz demo to my answer
– jo_va
Mar 28 at 9:29
@Pierrick Martellière, I provided a short stackblitz demo to my answer
– jo_va
Mar 28 at 9:29
1
1
@Pierrick Martellière, no problem!
– jo_va
Mar 28 at 9:53
@Pierrick Martellière, no problem!
– jo_va
Mar 28 at 9:53
|
show 12 more comments
Turns out there was another input in the bottom of my template that was used when the first input was clicked. The input event now triggers well.
Sorry for my stupidity and thanks to everyone for the time and patience.
add a comment
|
Turns out there was another input in the bottom of my template that was used when the first input was clicked. The input event now triggers well.
Sorry for my stupidity and thanks to everyone for the time and patience.
add a comment
|
Turns out there was another input in the bottom of my template that was used when the first input was clicked. The input event now triggers well.
Sorry for my stupidity and thanks to everyone for the time and patience.
Turns out there was another input in the bottom of my template that was used when the first input was clicked. The input event now triggers well.
Sorry for my stupidity and thanks to everyone for the time and patience.
answered Mar 28 at 9:55
Pierrick MartellièrePierrick Martellière
5159 silver badges30 bronze badges
5159 silver badges30 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55393810%2fangular-5-why-is-my-input-property-undefined%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
There is not an initialization in this example.
– JoseJimRin
Mar 28 at 9:13
2
You should use @ViewChild if you want to get reference to the input field.
– iamjc015
Mar 28 at 9:15
@iamjc015 you're right, now I get the input. But the main problem is that the input event is not triggered when i type on the input.
– Pierrick Martellière
Mar 28 at 9:24