aboutsummaryrefslogtreecommitdiffstats
path: root/src/directives.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/directives.js')
-rw-r--r--src/directives.js33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/directives.js b/src/directives.js
index 53d03573..61bb6139 100644
--- a/src/directives.js
+++ b/src/directives.js
@@ -212,9 +212,10 @@ angularDirective("ng:bind", function(expression, element){
element.addClass('ng-binding');
return ['$exceptionHandler', '$parse', '$element', function($exceptionHandler, $parse, element) {
var exprFn = $parse(expression),
- lastValue = Number.NaN;
+ lastValue = Number.NaN,
+ scope = this;
- this.$watch(function(scope) {
+ scope.$watch(function() {
// TODO(misko): remove error handling https://github.com/angular/angular.js/issues/347
var value, html, isHtml, isDomElement,
hadOwnElement = scope.hasOwnProperty('$element'),
@@ -305,8 +306,10 @@ angularDirective("ng:bind-template", function(expression, element){
element.addClass('ng-binding');
var templateFn = compileBindTemplate(expression);
return function(element) {
- var lastValue;
- this.$watch(function(scope) {
+ var lastValue,
+ scope = this;
+
+ scope.$watch(function() {
var value = templateFn(scope, element, true);
if (value != lastValue) {
element.text(value);
@@ -391,8 +394,10 @@ angularDirective("ng:bind-template", function(expression, element){
*/
angularDirective("ng:bind-attr", function(expression){
return function(element){
- var lastValue = {};
- this.$watch(function(scope){
+ var lastValue = {},
+ scope = this;
+
+ scope.$watch(function() {
var values = scope.$eval(expression);
for(var key in values) {
var value = compileBindTemplate(values[key])(scope, element);
@@ -518,7 +523,8 @@ angularDirective("ng:submit", function(expression, element) {
function ngClass(selector) {
return function(expression, element) {
return function(element) {
- this.$watch(expression, function(scope, newVal, oldVal) {
+ var scope = this;
+ scope.$watch(expression, function(newVal, oldVal) {
if (selector(scope.$index)) {
if (oldVal && (newVal !== oldVal)) {
element.removeClass(isArray(oldVal) ? oldVal.join(' ') : oldVal);
@@ -687,8 +693,9 @@ angularDirective("ng:class-even", ngClass(function(i){return i % 2 === 1;}));
</doc:example>
*/
angularDirective("ng:show", function(expression, element){
- return function(element){
- this.$watch(expression, function(scope, value){
+ return function(element) {
+ var scope = this;
+ scope.$watch(expression, function(value) {
element.css('display', toBoolean(value) ? '' : 'none');
});
};
@@ -727,8 +734,9 @@ angularDirective("ng:show", function(expression, element){
</doc:example>
*/
angularDirective("ng:hide", function(expression, element){
- return function(element){
- this.$watch(expression, function(scope, value){
+ return function(element) {
+ var scope = this;
+ scope.$watch(expression, function(value) {
element.css('display', toBoolean(value) ? 'none' : '');
});
};
@@ -768,7 +776,8 @@ angularDirective("ng:hide", function(expression, element){
*/
angularDirective("ng:style", function(expression, element) {
return function(element) {
- this.$watch(expression, function(scope, newStyles, oldStyles) {
+ var scope = this;
+ scope.$watch(expression, function(newStyles, oldStyles) {
if (oldStyles && (newStyles !== oldStyles)) {
forEach(oldStyles, function(val, style) { element.css(style, '');});
}