Template.templatename.onCreated
is mentioned in the documentation (along with the .onRendered
and .onDestroyed
methods).
But when I call these nothing happens. If i call Template.templatename.created
for instance, this works.
Any idea whats going on? Am I misreading something in the docs? is this a reference to something else ?
EDIT : I've just found this in the source :
.js#L65
on line 180, these are marked as deprecated in 1.1, but I'm still not getting any love from onCreated....
anyone know what I'm doing wrong?
Template.channels_admin.onCreated = function () {
// .... doesn't run
};
Template.templatename.onCreated
is mentioned in the documentation (along with the .onRendered
and .onDestroyed
methods).
But when I call these nothing happens. If i call Template.templatename.created
for instance, this works.
Any idea whats going on? Am I misreading something in the docs? is this a reference to something else ?
EDIT : I've just found this in the source :
https://github./meteor/meteor/blob/master/packages/blaze/template.js#L65
on line 180, these are marked as deprecated in 1.1, but I'm still not getting any love from onCreated....
anyone know what I'm doing wrong?
Template.channels_admin.onCreated = function () {
// .... doesn't run
};
Share
Improve this question
edited Jun 4, 2015 at 11:53
Phillip Cloud
25.7k12 gold badges72 silver badges91 bronze badges
asked May 23, 2015 at 20:04
bigmadwolfbigmadwolf
3,5393 gold badges31 silver badges47 bronze badges
5
- those sounds like events. – Daniel A. White Commented May 23, 2015 at 20:04
- They're template callback functions. – bigmadwolf Commented May 23, 2015 at 20:05
-
Is your project updated? Run
meteor update
to make sure of it. – Kyll Commented May 23, 2015 at 20:06 - hey, I get : This project is already at Meteor 1.1.0.2, the latest release. Your packages are at their latest patible versions. – bigmadwolf Commented May 23, 2015 at 20:10
- oh wait, code fail. = instead of a callback. – bigmadwolf Commented May 23, 2015 at 20:13
3 Answers
Reset to default 8Prior to meteor 1.0.4, created
was a function available to all templates that ran prior to any of the template logic (events, rendering, helpers, etc.). In 1.0.4, it was replaced with onCreated which is a function that registers callbacks (again each callback runs once before any template logic).
created
was left in place so as not to break existing code, but is considered deprecated in favor of onCreated
.
Because created
was a function on the template, it could be assigned via:
Template.myTemplate.created = function() {console.log('here');};
created
should not be called directly.
As you can see from the docs, onCreated
is called with a function like so:
Template.myTemplate.onCreated(function() {
console.log('hello');
});
The nice thing about onCreated
is that you can register multiple callbacks for the same template. In practice this may not e up often, however it's nice in cases where you need to attach to a template provided by an external package. This same logic applies to onRendered
and onDestroyed
.
As of meteor 1.1 the created, rednered and destroyed methods have been deprecated in place of onCreated, onRendered and onDestroyed.
Secondly there is a small change to the syntax previously it was declared like so :
Template.channels_admin.created = function () {
// .... this is deprecated
};
But as of 1.1 it should be declared like so :
Template.channels_admin.onCreated(function () {
// .... works like a charm.
});
created
is the old onCreated
.
use it like this .onCreated(function() {
this makes it really nice when you write packages.