Remove ng:watch

Closes#143
This commit is contained in:
Misko Hevery 2011-02-16 12:00:06 -05:00
parent fd6e5e3f31
commit 87cbf9f591
4 changed files with 1 additions and 78 deletions

View file

@ -14,7 +14,7 @@
To migrate simply remove the call to $init() and move any code you had before $init() to the
root controller.
- Change API angular.compile(..) to angular.compile(element)([scope], [cloneAttachFn])
- remove ng:watch directives since it encourages logic in the UI.
<a name="0.9.11"><a/>
# <angular/> 0.9.11 snow-maker (2011-02-08) #

View file

@ -516,51 +516,6 @@ angularDirective("ng:submit", function(expression, element) {
});
/**
* @workInProgress
* @ngdoc directive
* @name angular.directive.ng:watch
*
* @description
* The `ng:watch` allows you watch a variable and then execute
* an evaluation on variable change.
*
* @element ANY
* @param {expression} expression {@link guide.expression Expression} to eval.
*
* @example
* Notice that the counter is incremented
* every time you change the text.
<doc:example>
<doc:source>
<div ng:init="counter=0" ng:watch="name: counter = counter+1">
<input type="text" name="name" value="hello"><br/>
Change counter: {{counter}} Name: {{name}}
</div>
</doc:source>
<doc:scenario>
it('should check ng:watch', function(){
expect(using('.doc-example-live').binding('counter')).toBe('2');
using('.doc-example-live').input('name').enter('abc');
expect(using('.doc-example-live').binding('counter')).toBe('3');
});
</doc:scenario>
</doc:example>
*/
//TODO: delete me, since having watch in UI is logic in UI. (leftover form getangular)
angularDirective("ng:watch", function(expression, element){
return function(element){
var self = this;
parser(expression).watch()({
addListener:function(watch, exp){
self.$watch(watch, function(){
return exp(self);
}, element);
}
});
};
});
function ngClass(selector) {
return function(expression, element){
var existing = element[0].className + ' ';

View file

@ -226,12 +226,6 @@ describe('Binder', function(){
'</ul>', sortedHtml(a.view));
});
it('ExpandEntityTag', function(){
assertEquals(
'<div ng-entity="Person" ng:watch="$anchor.a:1"></div>',
this.compileToHtml('<div ng-entity="Person" ng:watch="$anchor.a:1"/>'));
});
it('DoNotOverwriteCustomAction', function(){
var html = this.compileToHtml('<input type="submit" value="Save" action="foo();">');
assertTrue(html.indexOf('action="foo();"') > 0 );
@ -612,20 +606,6 @@ describe('Binder', function(){
assertEquals("male", male.val());
});
it('ItShouldListenOnRightScope', function(){
var c = this.compile(
'<ul ng:init="counter=0; gCounter=0" ng:watch="w:counter=counter+1">' +
'<li ng:repeat="n in [1,2,4]" ng:watch="w:counter=counter+1;w:$root.gCounter=$root.gCounter+n"/></ul>');
c.scope.$eval();
assertEquals(1, c.scope.$get("counter"));
assertEquals(7, c.scope.$get("gCounter"));
c.scope.$set("w", "something");
c.scope.$eval();
assertEquals(2, c.scope.$get("counter"));
assertEquals(14, c.scope.$get("gCounter"));
});
it('ItShouldRepeatOnHashes', function(){
var x = this.compile('<ul><li ng:repeat="(k,v) in {a:0,b:1}" ng:bind=\"k + v\"></li></ul>');
x.scope.$eval();

View file

@ -137,18 +137,6 @@ describe("directive", function(){
expect(input.checked).toEqual(true);
});
it('should ng:watch', function(){
var scope = compile('<div ng:watch="i: count = count + 1" ng:init="count = 0">');
scope.$eval();
scope.$eval();
expect(scope.$get('count')).toEqual(1);
scope.$set('i', 0);
scope.$eval();
scope.$eval();
expect(scope.$get('count')).toEqual(2);
});
describe('ng:click', function(){
it('should get called on a click', function(){
var scope = compile('<div ng:click="clicked = true"></div>');