https://github.com/gwendall/meteor-templates-watch
Watch changes of template variables
https://github.com/gwendall/meteor-templates-watch
Last synced: 2 months ago
JSON representation
Watch changes of template variables
- Host: GitHub
- URL: https://github.com/gwendall/meteor-templates-watch
- Owner: gwendall
- Created: 2015-03-12T21:00:17.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-13T01:45:00.000Z (about 10 years ago)
- Last Synced: 2025-03-18T05:56:57.388Z (2 months ago)
- Language: JavaScript
- Size: 117 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Meteor Templates watch
=================Adds watch methods to template instances. Inspired by Angular's $watch function.
Installation
------------``` sh
meteor add gwendall:templates-watch
```Methods
----------**template.watch(var, callback)**
Watch changes of a single variable.**template.watchGroup(vars, callback)**
Watch changes of any variables in a set.Example
-------
``` javascript
Template.user.created = function() {
var tpl = this;
tpl.name = new ReactiveVar();
tpl.age = new ReactiveVar();
tpl.watch("name", function(value) {
console.log("The value of 'name' changed! It is now: " + value);
});
tpl.watchGroup(["name", "age"], function(values) {
console.log("The value of either 'name' or 'age' changed! Their new values are now the following.");
for (var k in values) {
console.log(k + ": " + values[k]);
})
});
}
```