0

I am using new angular 4 for learning and created project but I need help how to create object like anglarjs $scope.Param = {}; $scope.Param.MyId = "2231dddd";

How to do this in angular4 and post data into service please check below code

export class HomeComponent {
  public forecasts: WeatherForecast[];
  public EntityTypeList: EntityTypeList[];
  public Param: { id: string; };

  CreateDb() {
        this.Param.id = this.selectedValue;
        this.http.post('http://localhost:1101/api/db/CreateDb', this.Param).subscribe(result => {

        }, error => console.error(error));
    }
}
5
  • You want dynamic properties to add in Param? Commented Sep 28, 2018 at 7:53
  • you can directly use public Param = {} and then add property dynamically in it or can create model/interface to define type of object and then use it Commented Sep 28, 2018 at 7:54
  • yes i want add properties like this.Param.myname, this.Param.mynumber Commented Sep 28, 2018 at 7:54
  • nehalist.io/working-with-models-in-angular Commented Sep 28, 2018 at 7:54
  • direct use public Param {}; Commented Sep 28, 2018 at 7:56

2 Answers 2

4

You can then declare property like this

public Param : any = {};
Sign up to request clarification or add additional context in comments.

5 Comments

yeah, it can contain any object, array etc.
can i use this in html page
<input [(ngModel)]="Param.MyName" />
like this.. can i use like angularjs
Yes, you can set into input like you asked in comment.
0

Or if your param object is a key value pair of string, you can use:

public param: {[key: string]: string};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.