Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

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 ;)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...