0

I have a simple form in angular2 where the object which i pass to create the form should be of interface type...I have made a small plunker demo here http://plnkr.co/edit/GXyZfXenDcDLiCWwjfYN?p=preview ...If the object passed is of type null then i want to call new instance but it is not happening... Is it possible to call new instance for interface...

interface  Cust {
label: string;
}

This is my interface and below is how i am calling new instance in my component

  Create(data:Cust){
if(data==null){
  data=new Cust();
}
    this.myForm = this.localfb.group({  
  'sku':  [data.label, Validators.required]  
}); 
}

Somebody please guide me in the right direction...

1 Answer 1

1

You can't instantiate an interface. You want a class, not an interface. If you look at the JavaScript output, you'll see that an interface doesn't actually create any output, while a closure is created for a class.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @rgvassar...yea i have implemented using class...Thanks

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.