Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

angular - How can I pass an array to another component?

I have array FidId of string, i need to pass this array to use in another component

 public AddSelection(layer: VectorLayer, map:Map){
    this.vectorSource = layer;
      //start select
      var FidId:string[] = [];
      var FeatureFind = false;
      var select = new Select();

      map.addInteraction(select);
      var selectedFeature = select.getFeatures();

      this.dragBox = new DragBox({
        condition:(condition as any).platformModifierKeyOnly
      });
      map.addInteraction(this.dragBox);

      this.dragBox.on('boxend', () => {
        var extent = this.dragBox.getGeometry().getExtent();
        this.vectorSource.forEachFeatureIntersectingExtent(extent, function(feature) {
          FeatureFind = true;
          selectedFeature.push(feature);
          FidId.push(feature.get('id'));
        });

        if(FeatureFind)
        this.dialog.open(DialogData2Component);
        
      });
      this.dragBox.on('boxstart',()=>{
        selectedFeature.clear();
        FeatureFind = false;
        FidId = [];
      });
      //end select

  }

This is where i need it

Detail

I am new in the angular, so please help :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

the way i handled passing any arguments from my child to parent (looks to me thats what you need here)

first in my child component i define my eventEmitter and initialise my array which i want to pass to my parent

//child component.ts
array: any[] = [];
@Output() passArray = new Eventemitter

then i write a function which calls my eventemitter and emit my array like this

// child component.ts
emitArray() {
  this.passArray.emit(array);
}

Now i go into the HTML of my parent component where my child component is located here i can listen to the eventEmitter by putting it into brackets like this

// parent component.html
<custom-component (passArray)="yourFunction($event)"><custom-component>

// parent component.ts
yourFunction(parameter) {
  do.something()
}

so once the passArray.emit is called our parent component which is listening to it in the html executes the "yourFunction" whith the parameters which it gets from the $event. the $event is our data which we passed in our child component. for more detailed information on how to pass data around in angular you can read throught the docs on https://angular.io/docs. they do a good job explaining many topics :) (better than me :D)

this is one of my first answers so sry if its a bit messy :) i hope i was able to help ;)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...