'Angular: Can I pass values from the console to a component like how a parent component passes a value to its child?
For example, a parent component can pass in a value to its child component like below in its html file:
[name]='Ben'
As I'm trying to do several tests with a whole bunch of properties, is there a way to do it more efficiently besides doing it via query parameters? Could I do it via the console instead by placing an observable and maybe there's a function I can call in the console that takes in json format. So for example i can call this in the console:
dothis("listOfThings":[{"name":'Ben', "age":'30'}])
Thanks,
Ben
Solution 1:[1]
One way to go after this could be:
- Create an array that contains your "bunch of properties" in the component class
- Create a button in the template
- Add event listener to button
- On click, the button triggers a method in the component class that does what you need
By the way, your first example is data binding:
[name]='Ben'
If you don't use @Input you won't pass anything from parent to child. Here is an example. Maybe you are familiar with this. Forgive me if this is redundant.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lorenzo |
