简体   繁体   中英

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

One way to go after this could be:

  1. Create an array that contains your "bunch of properties" in the component class
  2. Create a button in the template
  3. Add event listener to button
  4. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM