Justin
Justin

Reputation: 45330

How to inherit a view in Ember.js

I have a view in Ember.js that looks like:

MyApp.LoginView = Ember.View.extend({
  templateName: 'login',
  didInsertElement: function() {
    $("body").addClass("light-bg");
    $("footer").css("display", "none");
    $("input[name=email]").focus();
  },
  willDestroyElement: function() {
    $("body").removeClass("light-bg");
    $("footer").css("display", "block");
  }
});

I need another view which is exactly the same, except it is called ForgotPassword, thus the only difference is the templateName.

Is there a way in Ember.js, I can say ForgotPassword inherits Login, and then just set templateName to forgotPassword?

Thanks.

Upvotes: 1

Views: 443

Answers (1)

MilkyWayJoe
MilkyWayJoe

Reputation: 9092

You can simply extend from the view you just created:

MyApp.YourOtherView = MyApp.LoginView.extend({
   // whatever you do here will be applied to `YourOtherView` only.. so
   templateName: 'other/template'
});

Upvotes: 2

Related Questions