Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I append the value of emberjs variable in object to my anchor tag href?

I want something like below

<a href="/Admin/MenuEdit/{{ResAdmin.adminController.selectionMenu}}">Edit Selected Menu</a>

selectionMenu is a variable in ResAdmin.adminController Ember Object.

like image 822
Kapil Garg Avatar asked Dec 14 '25 16:12

Kapil Garg


1 Answers

In order to declare a binding for an attribute, you'll need to use bindAttr. You can use this helper to bind an attribute either to a global path or to a variable in the current context, such as your view.

For instance, you might have a template like this:

<a {{bindAttr href="menuUrl"}}>Edit Selected Menu</a>

Which is bound to a property in your view, like this:

App.MyView = Ember.View.extend({
    menuUrl: function() {
        return "/Admin/MenuEdit/" + this.get("App.adminController.selectionMenu");
    }.property("App.adminController.selectionMenu)            
});

I created a fiddle for this example. ​

like image 78
Dan Gebhardt Avatar answered Dec 16 '25 06:12

Dan Gebhardt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!