I'm trying the use the link-to helper to open a dynamic link in a new tab, but so far it's not working.
I'm using LinkView for that and I can see the target attribute in my link, but it doesn't open the url in a new tab but in the current one.
Here is my code :
The template :
{{#link-to "page.edit" id target="_blank"}}EDIT{{/link-to}}
The LinkView :
Ember.LinkView.reopen({
attributeBindings: ['target']
});
This is what it generate when I inspect it :
<a id="ember468" class="ember-view" href="#/pages/1/edit" target="_blank">EDIT</a>
Do I miss something?
Thanks for the help.
The attribute target is already part of Ember.LinkView. Get rid of the reopen code and the rest is working: http://emberjs.jsbin.com/sumiwa/1/edit
Related
I'm using ember-intl and would like to translate html (href with link):
en-us.json:
{
"sign-up": "Didn't get it? check your spam folder, or try to '<a {myLink}>'send a new passcode'</a>'",
}
My controller has an action that is called: signUp:
actions: {
signUp: function() {
console.log('success');
},
}
In my hbs file, I tried:
{{{t 'sign-up' myLink=(action 'signUp')}}}
The text was set, and the link looks as a link, but when I click on this link, the log is not written.
Any help appreciated!
Check this thread in stackoverflow:
Combine linkTo and action helpers in Ember.js
probably after installing the library
ember-link-action
you can do something like
{{#link-to 'other-route' invokeAction=(action 'signUp')}}
{{t 'sign-up'}}
{{/link-to}}
I am new to emberJS and I am trying to open a new page like 'www.google.com' from one of my page where I have my link specified in my HBS template like below.
{{#link-to 'applications.google' tagName="li"}}Google{{/link-to}}
I tried to insert the {{action}} helper inside the tag also, and wrote an action method in the controller, yet it didn't work. Not sure. Please help.
You can use normal anchor tag with full URL with protocol.
<a href='http://www.google.com'> example </a>
I did added an action helper in the HRef tag like
And in the Ember Controller I included an action as
actions: {
openGoogle() {
window.open("google.com");
}
}
It works!!!
I have a template that has a a tag with an id and based on id the css applies style to this a href. I would like to use the LinkTo helper for this tag and id set to the one it has now. Helper LinkTo in Ember generates a link. I need to set an id on this a link for example:
<a href='...' id=xyz>
How to acomplish it?
You can just pass HTML attributes to the linkTo helper:
{{#linkTo 'some.route' id="xyz"}}Link text{{/linkTo}}
I would like to be able to swap views in a each helper using Ember.ContainerView.
{{#each itemController="person"}}
<li>{{view Ember.ContainerView currentViewBinding="cv"}}</li>
{{/each}}
It yields the following error:
Something you did caused a view to re-render after it rendered but before it was inserted into the DOM
It does work when I strip off the each helper.
I know there is other ways to do that but it seems to me that it's a good use case for a ContainerView.
Here is the jsFiddle : http://jsfiddle.net/fblanvil/Mr3D7/2/
Something you did caused a view to re-render after it rendered but before it was inserted into the DOM
I found the problem, have a look at your modified and working jsfiddle.
Basically what you where doing wrong and thus the error was that you where calling create which should be rather extend.
See here for the changed part:
...
cv: Ember.View.extend({
templateName: 'name'
})
...
Hope it helps.
I currently have this template
{{#each model}}
{{#linkTo object this}}{{name}}{{/linkTo}}
{{/each}}
which creates
<a href="path/#/objectid"/>
This does not cause a model reload, but a page refresh with that url does.
How can I make a link in my template with a full url?
<a href="path/objects/{{id}}">{{name}}</>
does not work, because {{id}} does not seem to fully resolve inside the quotation marks, so I get something like:
path/objects/<script id="metamorph-5-start....
I have seen answers hinting at adjusting setupController, but what if I do not want to reload the model every time? It would be nice to have control over this from the templating side, i.e. using {{#linkTo}} when no reload is needed and some other trick when a reload is needed. Is there an easy way to create a full url based on model parameters in handlebars?
This is may not be a full solution to your problem, but as for this part:
does not work, because {{id}} does not seem to fully resolve inside the quotation marks, so I get something like:
there is help:
<a href="path/objects/{{unbound id}}">{{name}}</>
Using unbound does not put the script metamorph tag's around the property.
Hope it helps you to tackle down your problem.
I figured it out - although without changing the url, so I am still using a normal {{#linkTo...}}.
As mentioned in How to reload an ember data record?, record.reload() can be used - it works for me like this:
App.ObjectRoute = Ember.Route.extend({
...
setupController: function(controller, model) {
var record = App.Object.find(model.id);
record.reload();
controller.set("model", record);
},
});
If there was an easy alternative using a modified url, I would still be interested in finding out.