mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
refactor(compiler) turn compiler into a service
BREAK - remove angular.compile() since the compile method is now a service and needs to be injected
This commit is contained in:
parent
d9b58f23f6
commit
d12df0d360
16 changed files with 695 additions and 686 deletions
|
|
@ -854,11 +854,6 @@ function toBoolean(value) {
|
|||
}
|
||||
|
||||
|
||||
/** @name angular.compile */
|
||||
function compile(element) {
|
||||
return new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget)
|
||||
.compile(element);
|
||||
}
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
|
|
@ -956,7 +951,7 @@ function angularInit(config, document){
|
|||
injector = createInjector(),
|
||||
scope = injector('$rootScope');
|
||||
|
||||
compile(element)(scope);
|
||||
injector('$compile')(element)(scope);
|
||||
scope.$apply();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ angularService('$browser', function($log, $sniffer) {
|
|||
extend(angular, {
|
||||
// disabled for now until we agree on public name
|
||||
//'annotate': annotate,
|
||||
'compile': compile,
|
||||
'copy': copy,
|
||||
'extend': extend,
|
||||
'equals': equals,
|
||||
|
|
|
|||
|
|
@ -1,307 +1,321 @@
|
|||
'use strict';
|
||||
|
||||
/**
|
||||
* Template provides directions an how to bind to a given element.
|
||||
* It contains a list of init functions which need to be called to
|
||||
* bind to a new instance of elements. It also provides a list
|
||||
* of child paths which contain child templates
|
||||
*/
|
||||
function Template() {
|
||||
this.paths = [];
|
||||
this.children = [];
|
||||
this.linkFns = [];
|
||||
this.newScope = false;
|
||||
}
|
||||
// TODO(misko): temporary services to get the compiler working;
|
||||
angularService('$textMarkup', valueFn(angularTextMarkup));
|
||||
angularService('$attrMarkup', valueFn(angularAttrMarkup));
|
||||
angularService('$directive', valueFn(angularDirective));
|
||||
angularService('$widget', valueFn(angularWidget));
|
||||
|
||||
Template.prototype = {
|
||||
link: function(element, scope) {
|
||||
var childScope = scope;
|
||||
if (this.newScope) {
|
||||
childScope = isFunction(this.newScope) ? scope.$new(this.newScope(scope)) : scope.$new();
|
||||
element.data($$scope, childScope);
|
||||
}
|
||||
forEach(this.linkFns, function(fn) {
|
||||
try {
|
||||
childScope.$service.invoke(childScope, fn, [element]);
|
||||
} catch (e) {
|
||||
childScope.$service('$exceptionHandler')(e);
|
||||
}
|
||||
});
|
||||
var i,
|
||||
childNodes = element[0].childNodes,
|
||||
children = this.children,
|
||||
paths = this.paths,
|
||||
length = paths.length;
|
||||
for (i = 0; i < length; i++) {
|
||||
// sometimes `element` can be modified by one of the linker functions in `this.linkFns`
|
||||
// and childNodes may be added or removed
|
||||
// TODO: element structure needs to be re-evaluated if new children added
|
||||
// if the childNode still exists
|
||||
if (childNodes[paths[i]])
|
||||
children[i].link(jqLite(childNodes[paths[i]]), childScope);
|
||||
else
|
||||
delete paths[i]; // if child no longer available, delete path
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
addLinkFn:function(linkingFn) {
|
||||
if (linkingFn) {
|
||||
this.linkFns.push(linkingFn);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
addChild: function(index, template) {
|
||||
if (template) {
|
||||
this.paths.push(index);
|
||||
this.children.push(template);
|
||||
}
|
||||
},
|
||||
|
||||
empty: function() {
|
||||
return this.linkFns.length === 0 && this.paths.length === 0;
|
||||
angularServiceInject('$compile', function($injector, $exceptionHandler, $textMarkup, $attrMarkup, $directive, $widget){
|
||||
/**
|
||||
* Template provides directions an how to bind to a given element.
|
||||
* It contains a list of init functions which need to be called to
|
||||
* bind to a new instance of elements. It also provides a list
|
||||
* of child paths which contain child templates
|
||||
*/
|
||||
function Template() {
|
||||
this.paths = [];
|
||||
this.children = [];
|
||||
this.linkFns = [];
|
||||
this.newScope = false;
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////
|
||||
//Compiler
|
||||
//////////////////////////////////
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name angular.compile
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* Compiles a piece of HTML string or DOM into a template and produces a template function, which
|
||||
* can then be used to link {@link angular.scope scope} and the template together.
|
||||
*
|
||||
* The compilation is a process of walking the DOM tree and trying to match DOM elements to
|
||||
* {@link angular.markup markup}, {@link angular.attrMarkup attrMarkup},
|
||||
* {@link angular.widget widgets}, and {@link angular.directive directives}. For each match it
|
||||
* executes corresponding markup, attrMarkup, widget or directive template function and collects the
|
||||
* instance functions into a single template function which is then returned.
|
||||
*
|
||||
* The template function can then be used once to produce the view or as it is the case with
|
||||
* {@link angular.widget.@ng:repeat repeater} many-times, in which case each call results in a view
|
||||
* that is a DOM clone of the original template.
|
||||
*
|
||||
<pre>
|
||||
// compile the entire window.document and give me the scope bound to this template.
|
||||
var rootScope = angular.compile(window.document)();
|
||||
|
||||
// compile a piece of html
|
||||
var rootScope2 = angular.compile('<div ng:click="clicked = true">click me</div>')();
|
||||
|
||||
// compile a piece of html and retain reference to both the dom and scope
|
||||
var template = angular.element('<div ng:click="clicked = true">click me</div>'),
|
||||
scope = angular.compile(template)();
|
||||
// at this point template was transformed into a view
|
||||
</pre>
|
||||
*
|
||||
*
|
||||
* @param {string|DOMElement} element Element or HTML to compile into a template function.
|
||||
* @returns {function(scope[, cloneAttachFn])} a template function which is used to bind template
|
||||
* (a DOM element/tree) to a scope. Where:
|
||||
*
|
||||
* * `scope` - A {@link angular.scope Scope} to bind to.
|
||||
* * `cloneAttachFn` - If `cloneAttachFn` is provided, then the link function will clone the
|
||||
* `template` and call the `cloneAttachFn` function allowing the caller to attach the
|
||||
* cloned elements to the DOM document at the appropriate place. The `cloneAttachFn` is
|
||||
* called as: <br/> `cloneAttachFn(clonedElement, scope)` where:
|
||||
*
|
||||
* * `clonedElement` - is a clone of the original `element` passed into the compiler.
|
||||
* * `scope` - is the current scope with which the linking function is working with.
|
||||
*
|
||||
* Calling the template function returns the element of the template. It is either the original element
|
||||
* passed in, or the clone of the element if the `cloneAttachFn` is provided.
|
||||
*
|
||||
* It is important to understand that the returned scope is "linked" to the view DOM, but no linking
|
||||
* (instance) functions registered by {@link angular.directive directives} or
|
||||
* {@link angular.widget widgets} found in the template have been executed yet. This means that the
|
||||
* view is likely empty and doesn't contain any values that result from evaluation on the scope. To
|
||||
* bring the view to life, the scope needs to run through a $digest phase which typically is done by
|
||||
* Angular automatically, except for the case when an application is being
|
||||
* {@link guide/dev_guide.bootstrap.manual_bootstrap} manually bootstrapped, in which case the
|
||||
* $digest phase must be invoked by calling {@link angular.scope.$apply}.
|
||||
*
|
||||
* If you need access to the bound view, there are two ways to do it:
|
||||
*
|
||||
* - If you are not asking the linking function to clone the template, create the DOM element(s)
|
||||
* before you send them to the compiler and keep this reference around.
|
||||
* <pre>
|
||||
* var scope = angular.injector()('$rootScope');
|
||||
* var element = angular.compile('<p>{{total}}</p>')(scope);
|
||||
* </pre>
|
||||
*
|
||||
* - if on the other hand, you need the element to be cloned, the view reference from the original
|
||||
* example would not point to the clone, but rather to the original template that was cloned. In
|
||||
* this case, you can access the clone via the cloneAttachFn:
|
||||
* <pre>
|
||||
* var original = angular.element('<p>{{total}}</p>'),
|
||||
* scope = someParentScope.$new(),
|
||||
* clone;
|
||||
*
|
||||
* angular.compile(original)(scope, function(clonedElement, scope) {
|
||||
* clone = clonedElement;
|
||||
* //attach the clone to DOM document at the right place
|
||||
* });
|
||||
*
|
||||
* //now we have reference to the cloned DOM via `clone`
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* Compiler Methods For Widgets and Directives:
|
||||
*
|
||||
* The following methods are available for use when you write your own widgets, directives,
|
||||
* and markup. (Recall that the compile function's this is a reference to the compiler.)
|
||||
*
|
||||
* `compile(element)` - returns linker -
|
||||
* Invoke a new instance of the compiler to compile a DOM element and return a linker function.
|
||||
* You can apply the linker function to the original element or a clone of the original element.
|
||||
* The linker function returns a scope.
|
||||
*
|
||||
* * `comment(commentText)` - returns element - Create a comment element.
|
||||
*
|
||||
* * `element(elementName)` - returns element - Create an element by name.
|
||||
*
|
||||
* * `text(text)` - returns element - Create a text element.
|
||||
*
|
||||
* * `descend([set])` - returns descend state (true or false). Get or set the current descend
|
||||
* state. If true the compiler will descend to children elements.
|
||||
*
|
||||
* * `directives([set])` - returns directive state (true or false). Get or set the current
|
||||
* directives processing state. The compiler will process directives only when directives set to
|
||||
* true.
|
||||
*
|
||||
* For information on how the compiler works, see the
|
||||
* {@link guide/dev_guide.compiler Angular HTML Compiler} section of the Developer Guide.
|
||||
*/
|
||||
function Compiler(markup, attrMarkup, directives, widgets){
|
||||
this.markup = markup;
|
||||
this.attrMarkup = attrMarkup;
|
||||
this.directives = directives;
|
||||
this.widgets = widgets;
|
||||
}
|
||||
|
||||
Compiler.prototype = {
|
||||
compile: function(templateElement) {
|
||||
templateElement = jqLite(templateElement);
|
||||
var index = 0,
|
||||
template,
|
||||
parent = templateElement.parent();
|
||||
if (templateElement.length > 1) {
|
||||
// https://github.com/angular/angular.js/issues/338
|
||||
throw Error("Cannot compile multiple element roots: " +
|
||||
jqLite('<div>').append(templateElement.clone()).html());
|
||||
}
|
||||
if (parent && parent[0]) {
|
||||
parent = parent[0];
|
||||
for(var i = 0; i < parent.childNodes.length; i++) {
|
||||
if (parent.childNodes[i] == templateElement[0]) {
|
||||
index = i;
|
||||
Template.prototype = {
|
||||
link: function(element, scope) {
|
||||
var childScope = scope;
|
||||
if (this.newScope) {
|
||||
childScope = isFunction(this.newScope) ? scope.$new(this.newScope(scope)) : scope.$new();
|
||||
element.data($$scope, childScope);
|
||||
}
|
||||
forEach(this.linkFns, function(fn) {
|
||||
try {
|
||||
childScope.$service.invoke(childScope, fn, [element]);
|
||||
} catch (e) {
|
||||
$exceptionHandler(e);
|
||||
}
|
||||
});
|
||||
var i,
|
||||
childNodes = element[0].childNodes,
|
||||
children = this.children,
|
||||
paths = this.paths,
|
||||
length = paths.length;
|
||||
for (i = 0; i < length; i++) {
|
||||
// sometimes `element` can be modified by one of the linker functions in `this.linkFns`
|
||||
// and childNodes may be added or removed
|
||||
// TODO: element structure needs to be re-evaluated if new children added
|
||||
// if the childNode still exists
|
||||
if (childNodes[paths[i]])
|
||||
children[i].link(jqLite(childNodes[paths[i]]), childScope);
|
||||
else
|
||||
delete paths[i]; // if child no longer available, delete path
|
||||
}
|
||||
}
|
||||
template = this.templatize(templateElement, index) || new Template();
|
||||
return function(scope, cloneConnectFn){
|
||||
assertArg(scope, 'scope');
|
||||
// important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
|
||||
// and sometimes changes the structure of the DOM.
|
||||
var element = cloneConnectFn
|
||||
? JQLitePrototype.clone.call(templateElement) // IMPORTANT!!!
|
||||
: templateElement;
|
||||
element.data($$scope, scope);
|
||||
scope.$element = element;
|
||||
(cloneConnectFn||noop)(element, scope);
|
||||
template.link(element, scope);
|
||||
return element;
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
templatize: function(element, elementIndex){
|
||||
var self = this,
|
||||
widget,
|
||||
fn,
|
||||
directiveFns = self.directives,
|
||||
descend = true,
|
||||
directives = true,
|
||||
elementName = nodeName_(element),
|
||||
elementNamespace = elementName.indexOf(':') > 0 ? lowercase(elementName).replace(':', '-') : '',
|
||||
template,
|
||||
selfApi = {
|
||||
compile: bind(self, self.compile),
|
||||
descend: function(value){ if(isDefined(value)) descend = value; return descend;},
|
||||
directives: function(value){ if(isDefined(value)) directives = value; return directives;},
|
||||
scope: function(value){ if(isDefined(value)) template.newScope = template.newScope || value; return template.newScope;}
|
||||
};
|
||||
element.addClass(elementNamespace);
|
||||
template = new Template();
|
||||
eachAttribute(element, function(value, name){
|
||||
if (!widget) {
|
||||
if ((widget = self.widgets('@' + name))) {
|
||||
element.addClass('ng-attr-widget');
|
||||
widget = bind(selfApi, widget, value, element);
|
||||
}
|
||||
|
||||
addLinkFn:function(linkingFn) {
|
||||
if (linkingFn) {
|
||||
this.linkFns.push(linkingFn);
|
||||
}
|
||||
});
|
||||
if (!widget) {
|
||||
if ((widget = self.widgets(elementName))) {
|
||||
if (elementNamespace)
|
||||
element.addClass('ng-widget');
|
||||
widget = bind(selfApi, widget, element);
|
||||
},
|
||||
|
||||
|
||||
addChild: function(index, template) {
|
||||
if (template) {
|
||||
this.paths.push(index);
|
||||
this.children.push(template);
|
||||
}
|
||||
},
|
||||
|
||||
empty: function() {
|
||||
return this.linkFns.length === 0 && this.paths.length === 0;
|
||||
}
|
||||
if (widget) {
|
||||
descend = false;
|
||||
directives = false;
|
||||
var parent = element.parent();
|
||||
template.addLinkFn(widget.call(selfApi, element));
|
||||
};
|
||||
|
||||
///////////////////////////////////
|
||||
//Compiler
|
||||
//////////////////////////////////
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name angular.compile
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* Compiles a piece of HTML string or DOM into a template and produces a template function, which
|
||||
* can then be used to link {@link angular.scope scope} and the template together.
|
||||
*
|
||||
* The compilation is a process of walking the DOM tree and trying to match DOM elements to
|
||||
* {@link angular.markup markup}, {@link angular.attrMarkup attrMarkup},
|
||||
* {@link angular.widget widgets}, and {@link angular.directive directives}. For each match it
|
||||
* executes corresponding markup, attrMarkup, widget or directive template function and collects the
|
||||
* instance functions into a single template function which is then returned.
|
||||
*
|
||||
* The template function can then be used once to produce the view or as it is the case with
|
||||
* {@link angular.widget.@ng:repeat repeater} many-times, in which case each call results in a view
|
||||
* that is a DOM clone of the original template.
|
||||
*
|
||||
<pre>
|
||||
// compile the entire window.document and give me the scope bound to this template.
|
||||
var rootScope = angular.compile(window.document)();
|
||||
|
||||
// compile a piece of html
|
||||
var rootScope2 = angular.compile('<div ng:click="clicked = true">click me</div>')();
|
||||
|
||||
|
||||
// compile a piece of html and retain reference to both the dom and scope
|
||||
var template = angular.element('<div ng:click="clicked = true">click me</div>'),
|
||||
scope = angular.compile(template)();
|
||||
// at this point template was transformed into a view
|
||||
</pre>
|
||||
*
|
||||
*
|
||||
* @param {string|DOMElement} element Element or HTML to compile into a template function.
|
||||
* @returns {function(scope[, cloneAttachFn])} a template function which is used to bind template
|
||||
* (a DOM element/tree) to a scope. Where:
|
||||
*
|
||||
* * `scope` - A {@link angular.scope Scope} to bind to.
|
||||
* * `cloneAttachFn` - If `cloneAttachFn` is provided, then the link function will clone the
|
||||
* `template` and call the `cloneAttachFn` function allowing the caller to attach the
|
||||
* cloned elements to the DOM document at the appropriate place. The `cloneAttachFn` is
|
||||
* called as: <br/> `cloneAttachFn(clonedElement, scope)` where:
|
||||
*
|
||||
* * `clonedElement` - is a clone of the original `element` passed into the compiler.
|
||||
* * `scope` - is the current scope with which the linking function is working with.
|
||||
*
|
||||
* Calling the template function returns the element of the template. It is either the original element
|
||||
* passed in, or the clone of the element if the `cloneAttachFn` is provided.
|
||||
*
|
||||
* It is important to understand that the returned scope is "linked" to the view DOM, but no linking
|
||||
* (instance) functions registered by {@link angular.directive directives} or
|
||||
* {@link angular.widget widgets} found in the template have been executed yet. This means that the
|
||||
* view is likely empty and doesn't contain any values that result from evaluation on the scope. To
|
||||
* bring the view to life, the scope needs to run through a $digest phase which typically is done by
|
||||
* Angular automatically, except for the case when an application is being
|
||||
* {@link guide/dev_guide.bootstrap.manual_bootstrap} manually bootstrapped, in which case the
|
||||
* $digest phase must be invoked by calling {@link angular.scope.$apply}.
|
||||
*
|
||||
* If you need access to the bound view, there are two ways to do it:
|
||||
*
|
||||
* - If you are not asking the linking function to clone the template, create the DOM element(s)
|
||||
* before you send them to the compiler and keep this reference around.
|
||||
* <pre>
|
||||
* var scope = angular.injector()('$rootScope');
|
||||
* var element = angular.compile('<p>{{total}}</p>')(scope);
|
||||
* </pre>
|
||||
*
|
||||
* - if on the other hand, you need the element to be cloned, the view reference from the original
|
||||
* example would not point to the clone, but rather to the original template that was cloned. In
|
||||
* this case, you can access the clone via the cloneAttachFn:
|
||||
* <pre>
|
||||
* var original = angular.element('<p>{{total}}</p>'),
|
||||
* scope = someParentScope.$new(),
|
||||
* clone;
|
||||
*
|
||||
* angular.compile(original)(scope, function(clonedElement, scope) {
|
||||
* clone = clonedElement;
|
||||
* //attach the clone to DOM document at the right place
|
||||
* });
|
||||
*
|
||||
* //now we have reference to the cloned DOM via `clone`
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* Compiler Methods For Widgets and Directives:
|
||||
*
|
||||
* The following methods are available for use when you write your own widgets, directives,
|
||||
* and markup. (Recall that the compile function's this is a reference to the compiler.)
|
||||
*
|
||||
* `compile(element)` - returns linker -
|
||||
* Invoke a new instance of the compiler to compile a DOM element and return a linker function.
|
||||
* You can apply the linker function to the original element or a clone of the original element.
|
||||
* The linker function returns a scope.
|
||||
*
|
||||
* * `comment(commentText)` - returns element - Create a comment element.
|
||||
*
|
||||
* * `element(elementName)` - returns element - Create an element by name.
|
||||
*
|
||||
* * `text(text)` - returns element - Create a text element.
|
||||
*
|
||||
* * `descend([set])` - returns descend state (true or false). Get or set the current descend
|
||||
* state. If true the compiler will descend to children elements.
|
||||
*
|
||||
* * `directives([set])` - returns directive state (true or false). Get or set the current
|
||||
* directives processing state. The compiler will process directives only when directives set to
|
||||
* true.
|
||||
*
|
||||
* For information on how the compiler works, see the
|
||||
* {@link guide/dev_guide.compiler Angular HTML Compiler} section of the Developer Guide.
|
||||
*/
|
||||
function Compiler(markup, attrMarkup, directives, widgets){
|
||||
this.markup = markup;
|
||||
this.attrMarkup = attrMarkup;
|
||||
this.directives = directives;
|
||||
this.widgets = widgets;
|
||||
}
|
||||
|
||||
Compiler.prototype = {
|
||||
compile: function(templateElement) {
|
||||
templateElement = jqLite(templateElement);
|
||||
var index = 0,
|
||||
template,
|
||||
parent = templateElement.parent();
|
||||
if (templateElement.length > 1) {
|
||||
// https://github.com/angular/angular.js/issues/338
|
||||
throw Error("Cannot compile multiple element roots: " +
|
||||
jqLite('<div>').append(templateElement.clone()).html());
|
||||
}
|
||||
if (parent && parent[0]) {
|
||||
element = jqLite(parent[0].childNodes[elementIndex]);
|
||||
}
|
||||
}
|
||||
if (descend){
|
||||
// process markup for text nodes only
|
||||
for(var i=0, child=element[0].childNodes;
|
||||
i<child.length; i++) {
|
||||
if (isTextNode(child[i])) {
|
||||
forEach(self.markup, function(markup){
|
||||
if (i<child.length) {
|
||||
var textNode = jqLite(child[i]);
|
||||
markup.call(selfApi, textNode.text(), textNode, element);
|
||||
}
|
||||
});
|
||||
parent = parent[0];
|
||||
for(var i = 0; i < parent.childNodes.length; i++) {
|
||||
if (parent.childNodes[i] == templateElement[0]) {
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
template = this.templatize(templateElement, index) || new Template();
|
||||
return function(scope, cloneConnectFn){
|
||||
assertArg(scope, 'scope');
|
||||
// important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
|
||||
// and sometimes changes the structure of the DOM.
|
||||
var element = cloneConnectFn
|
||||
? JQLitePrototype.clone.call(templateElement) // IMPORTANT!!!
|
||||
: templateElement;
|
||||
element.data($$scope, scope);
|
||||
scope.$element = element;
|
||||
(cloneConnectFn||noop)(element, scope);
|
||||
template.link(element, scope);
|
||||
return element;
|
||||
};
|
||||
},
|
||||
|
||||
if (directives) {
|
||||
// Process attributes/directives
|
||||
templatize: function(element, elementIndex){
|
||||
var self = this,
|
||||
widget,
|
||||
fn,
|
||||
directiveFns = self.directives,
|
||||
descend = true,
|
||||
directives = true,
|
||||
elementName = nodeName_(element),
|
||||
elementNamespace = elementName.indexOf(':') > 0 ? lowercase(elementName).replace(':', '-') : '',
|
||||
template,
|
||||
selfApi = {
|
||||
compile: bind(self, self.compile),
|
||||
descend: function(value){ if(isDefined(value)) descend = value; return descend;},
|
||||
directives: function(value){ if(isDefined(value)) directives = value; return directives;},
|
||||
scope: function(value){ if(isDefined(value)) template.newScope = template.newScope || value; return template.newScope;}
|
||||
};
|
||||
element.addClass(elementNamespace);
|
||||
template = new Template();
|
||||
eachAttribute(element, function(value, name){
|
||||
forEach(self.attrMarkup, function(markup){
|
||||
markup.call(selfApi, value, name, element);
|
||||
});
|
||||
});
|
||||
eachAttribute(element, function(value, name){
|
||||
name = lowercase(name);
|
||||
fn = directiveFns[name];
|
||||
if (fn) {
|
||||
element.addClass('ng-directive');
|
||||
template.addLinkFn((directiveFns[name]).call(selfApi, value, element));
|
||||
if (!widget) {
|
||||
if ((widget = self.widgets('@' + name))) {
|
||||
element.addClass('ng-attr-widget');
|
||||
widget = bind(selfApi, widget, value, element);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!widget) {
|
||||
if ((widget = self.widgets(elementName))) {
|
||||
if (elementNamespace)
|
||||
element.addClass('ng-widget');
|
||||
widget = bind(selfApi, widget, element);
|
||||
}
|
||||
}
|
||||
if (widget) {
|
||||
descend = false;
|
||||
directives = false;
|
||||
var parent = element.parent();
|
||||
template.addLinkFn(widget.call(selfApi, element));
|
||||
if (parent && parent[0]) {
|
||||
element = jqLite(parent[0].childNodes[elementIndex]);
|
||||
}
|
||||
}
|
||||
if (descend){
|
||||
// process markup for text nodes only
|
||||
for(var i=0, child=element[0].childNodes;
|
||||
i<child.length; i++) {
|
||||
if (isTextNode(child[i])) {
|
||||
forEach(self.markup, function(markup){
|
||||
if (i<child.length) {
|
||||
var textNode = jqLite(child[i]);
|
||||
markup.call(selfApi, textNode.text(), textNode, element);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (directives) {
|
||||
// Process attributes/directives
|
||||
eachAttribute(element, function(value, name){
|
||||
forEach(self.attrMarkup, function(markup){
|
||||
markup.call(selfApi, value, name, element);
|
||||
});
|
||||
});
|
||||
eachAttribute(element, function(value, name){
|
||||
name = lowercase(name);
|
||||
fn = directiveFns[name];
|
||||
if (fn) {
|
||||
element.addClass('ng-directive');
|
||||
template.addLinkFn((directiveFns[name]).call(selfApi, value, element));
|
||||
}
|
||||
});
|
||||
}
|
||||
// Process non text child nodes
|
||||
if (descend) {
|
||||
eachNode(element, function(child, i){
|
||||
template.addChild(i, self.templatize(child, i));
|
||||
});
|
||||
}
|
||||
return template.empty() ? null : template;
|
||||
}
|
||||
// Process non text child nodes
|
||||
if (descend) {
|
||||
eachNode(element, function(child, i){
|
||||
template.addChild(i, self.templatize(child, i));
|
||||
});
|
||||
}
|
||||
return template.empty() ? null : template;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
var compiler = new Compiler($textMarkup, $attrMarkup, $directive, $widget);
|
||||
return bind(compiler, compiler.compile);
|
||||
}, ['$injector', '$exceptionHandler', '$textMarkup', '$attrMarkup', '$directive', '$widget']);
|
||||
|
||||
|
||||
function eachNode(element, fn){
|
||||
var i, chldNodes = element[0].childNodes || [], chld;
|
||||
|
|
@ -325,4 +339,3 @@ function eachAttribute(element, fn){
|
|||
}
|
||||
forEachSorted(attrValue, fn);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -130,7 +130,8 @@ var NG_OPTIONS_REGEXP = /^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+
|
|||
angularWidget('select', function(element){
|
||||
this.directives(true);
|
||||
this.descend(true);
|
||||
return element.attr('ng:model') && annotate('$formFactory', function($formFactory, selectElement){
|
||||
return element.attr('ng:model') &&
|
||||
annotate('$formFactory', '$compile', function($formFactory, $compile, selectElement){
|
||||
var modelScope = this,
|
||||
match,
|
||||
form = $formFactory.forElement(selectElement),
|
||||
|
|
@ -245,7 +246,7 @@ angularWidget('select', function(element){
|
|||
// developer declared null option, so user should be able to select it
|
||||
nullOption = jqLite(option).remove();
|
||||
// compile the element since there might be bindings in it
|
||||
compile(nullOption)(modelScope);
|
||||
$compile(nullOption)(modelScope);
|
||||
}
|
||||
});
|
||||
selectElement.html(''); // clear contents
|
||||
|
|
|
|||
|
|
@ -423,7 +423,7 @@ describe('angular', function() {
|
|||
|
||||
|
||||
describe('directive', function() {
|
||||
it('should register directives with case-insensitive id', function() {
|
||||
it('should register directives with case-insensitive id', inject(function($compile) {
|
||||
angularDirective('ALLCAPS', function(val, el) {el.text('+' + val + '+')});
|
||||
angularDirective('lowercase', function(val, el) {el.text('-' + val + '-')});
|
||||
|
||||
|
|
@ -433,14 +433,14 @@ describe('angular', function() {
|
|||
'<span ALLCAPS="xx3"></span>' +
|
||||
'<span lowerCASE="XX4">xx4</span>' +
|
||||
'</div>');
|
||||
compile(el);
|
||||
$compile(el);
|
||||
expect(lowercase(sortedHtml(el))).toBe('<div>' +
|
||||
'<span allcaps="xx1">+xx1+</span>' +
|
||||
'<span allcaps="xx2">+xx2+</span>' +
|
||||
'<span allcaps="xx3">+xx3+</span>' +
|
||||
'<span lowercase="xx4">-xx4-</span>' +
|
||||
'</div>');
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -458,25 +458,25 @@ describe('angular', function() {
|
|||
});
|
||||
|
||||
describe('compile', function() {
|
||||
it('should link to existing node and create scope', inject(function($rootScope) {
|
||||
it('should link to existing node and create scope', inject(function($rootScope, $compile) {
|
||||
var template = angular.element('<div>{{greeting = "hello world"}}</div>');
|
||||
angular.compile(template)($rootScope);
|
||||
$compile(template)($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(template.text()).toEqual('hello world');
|
||||
expect($rootScope.greeting).toEqual('hello world');
|
||||
}));
|
||||
|
||||
it('should link to existing node and given scope', inject(function($rootScope) {
|
||||
it('should link to existing node and given scope', inject(function($rootScope, $compile) {
|
||||
var template = angular.element('<div>{{greeting = "hello world"}}</div>');
|
||||
angular.compile(template)($rootScope);
|
||||
$compile(template)($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(template.text()).toEqual('hello world');
|
||||
}));
|
||||
|
||||
it('should link to new node and given scope', inject(function($rootScope) {
|
||||
it('should link to new node and given scope', inject(function($rootScope, $compile) {
|
||||
var template = jqLite('<div>{{greeting = "hello world"}}</div>');
|
||||
|
||||
var templateFn = angular.compile(template);
|
||||
var templateFn = $compile(template);
|
||||
var templateClone = template.clone();
|
||||
|
||||
var element = templateFn($rootScope, function(clone){
|
||||
|
|
@ -490,9 +490,9 @@ describe('angular', function() {
|
|||
expect($rootScope.greeting).toEqual('hello world');
|
||||
}));
|
||||
|
||||
it('should link to cloned node and create scope', inject(function($rootScope) {
|
||||
it('should link to cloned node and create scope', inject(function($rootScope, $compile) {
|
||||
var template = jqLite('<div>{{greeting = "hello world"}}</div>');
|
||||
var element = angular.compile(template)($rootScope, noop);
|
||||
var element = $compile(template)($rootScope, noop);
|
||||
$rootScope.$digest();
|
||||
expect(template.text()).toEqual('');
|
||||
expect(element.text()).toEqual('hello world');
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ describe('Binder', function() {
|
|||
beforeEach(function() {
|
||||
this.compileToHtml = function (content) {
|
||||
var html;
|
||||
inject(function($rootScope){
|
||||
inject(function($rootScope, $compile){
|
||||
content = jqLite(content);
|
||||
angular.compile(content)($rootScope);
|
||||
$compile(content)($rootScope);
|
||||
html = sortedHtml(content);
|
||||
}).call(this);
|
||||
return html;
|
||||
|
|
@ -19,25 +19,25 @@ describe('Binder', function() {
|
|||
}
|
||||
});
|
||||
|
||||
it('BindUpdate', inject(function($rootScope) {
|
||||
angular.compile('<div ng:init="a=123"/>')($rootScope);
|
||||
it('BindUpdate', inject(function($rootScope, $compile) {
|
||||
$compile('<div ng:init="a=123"/>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
assertEquals(123, $rootScope.a);
|
||||
}));
|
||||
|
||||
it('ExecuteInitialization', inject(function($rootScope) {
|
||||
angular.compile('<div ng:init="a=123">')($rootScope);
|
||||
it('ExecuteInitialization', inject(function($rootScope, $compile) {
|
||||
$compile('<div ng:init="a=123">')($rootScope);
|
||||
assertEquals($rootScope.a, 123);
|
||||
}));
|
||||
|
||||
it('ExecuteInitializationStatements', inject(function($rootScope) {
|
||||
angular.compile('<div ng:init="a=123;b=345">')($rootScope);
|
||||
it('ExecuteInitializationStatements', inject(function($rootScope, $compile) {
|
||||
$compile('<div ng:init="a=123;b=345">')($rootScope);
|
||||
assertEquals($rootScope.a, 123);
|
||||
assertEquals($rootScope.b, 345);
|
||||
}));
|
||||
|
||||
it('ApplyTextBindings', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:bind="model.a">x</div>')($rootScope);
|
||||
it('ApplyTextBindings', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:bind="model.a">x</div>')($rootScope);
|
||||
$rootScope.model = {a:123};
|
||||
$rootScope.$apply();
|
||||
assertEquals('123', element.text());
|
||||
|
|
@ -51,7 +51,7 @@ describe('Binder', function() {
|
|||
assertEquals(this.compileToHtml("<b>{{b}}</b>"), '<b><span ng:bind="b"></span></b>');
|
||||
});
|
||||
|
||||
it('BindingSpaceConfusesIE', inject(function($rootScope) {
|
||||
it('BindingSpaceConfusesIE', inject(function($rootScope, $compile) {
|
||||
if (!msie) return;
|
||||
var span = document.createElement("span");
|
||||
span.innerHTML = ' ';
|
||||
|
|
@ -65,44 +65,44 @@ describe('Binder', function() {
|
|||
this.compileToHtml("<b>{{A}} x {{B}} ({{C}})</b>"));
|
||||
}));
|
||||
|
||||
it('BindingOfAttributes', inject(function($rootScope) {
|
||||
var element = angular.compile("<a href='http://s/a{{b}}c' foo='x'></a>")($rootScope);
|
||||
it('BindingOfAttributes', inject(function($rootScope, $compile) {
|
||||
var element = $compile("<a href='http://s/a{{b}}c' foo='x'></a>")($rootScope);
|
||||
var attrbinding = element.attr("ng:bind-attr");
|
||||
var bindings = fromJson(attrbinding);
|
||||
assertEquals("http://s/a{{b}}c", decodeURI(bindings.href));
|
||||
assertTrue(!bindings.foo);
|
||||
}));
|
||||
|
||||
it('MarkMultipleAttributes', inject(function($rootScope) {
|
||||
var element = angular.compile('<a href="http://s/a{{b}}c" foo="{{d}}"></a>')($rootScope);
|
||||
it('MarkMultipleAttributes', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<a href="http://s/a{{b}}c" foo="{{d}}"></a>')($rootScope);
|
||||
var attrbinding = element.attr("ng:bind-attr");
|
||||
var bindings = fromJson(attrbinding);
|
||||
assertEquals(bindings.foo, "{{d}}");
|
||||
assertEquals(decodeURI(bindings.href), "http://s/a{{b}}c");
|
||||
}));
|
||||
|
||||
it('AttributesNoneBound', inject(function($rootScope) {
|
||||
var a = angular.compile("<a href='abc' foo='def'></a>")($rootScope);
|
||||
it('AttributesNoneBound', inject(function($rootScope, $compile) {
|
||||
var a = $compile("<a href='abc' foo='def'></a>")($rootScope);
|
||||
assertEquals(a[0].nodeName, "A");
|
||||
assertTrue(!a.attr("ng:bind-attr"));
|
||||
}));
|
||||
|
||||
it('ExistingAttrbindingIsAppended', inject(function($rootScope) {
|
||||
var a = angular.compile("<a href='http://s/{{abc}}' ng:bind-attr='{\"b\":\"{{def}}\"}'></a>")($rootScope);
|
||||
it('ExistingAttrbindingIsAppended', inject(function($rootScope, $compile) {
|
||||
var a = $compile("<a href='http://s/{{abc}}' ng:bind-attr='{\"b\":\"{{def}}\"}'></a>")($rootScope);
|
||||
assertEquals('{"b":"{{def}}","href":"http://s/{{abc}}"}', a.attr('ng:bind-attr'));
|
||||
}));
|
||||
|
||||
it('AttributesAreEvaluated', inject(function($rootScope) {
|
||||
var a = angular.compile('<a ng:bind-attr=\'{"a":"a", "b":"a+b={{a+b}}"}\'></a>')($rootScope);
|
||||
it('AttributesAreEvaluated', inject(function($rootScope, $compile) {
|
||||
var a = $compile('<a ng:bind-attr=\'{"a":"a", "b":"a+b={{a+b}}"}\'></a>')($rootScope);
|
||||
$rootScope.$eval('a=1;b=2');
|
||||
$rootScope.$apply();
|
||||
assertEquals(a.attr('a'), 'a');
|
||||
assertEquals(a.attr('b'), 'a+b=3');
|
||||
}));
|
||||
|
||||
it('InputTypeButtonActionExecutesInScope', inject(function($rootScope) {
|
||||
it('InputTypeButtonActionExecutesInScope', inject(function($rootScope, $compile) {
|
||||
var savedCalled = false;
|
||||
var element = angular.compile(
|
||||
var element = $compile(
|
||||
'<input type="button" ng:click="person.save()" value="Apply">')($rootScope);
|
||||
$rootScope.person = {};
|
||||
$rootScope.person.save = function() {
|
||||
|
|
@ -112,9 +112,9 @@ describe('Binder', function() {
|
|||
assertTrue(savedCalled);
|
||||
}));
|
||||
|
||||
it('InputTypeButtonActionExecutesInScope2', inject(function($rootScope) {
|
||||
it('InputTypeButtonActionExecutesInScope2', inject(function($rootScope, $compile) {
|
||||
var log = "";
|
||||
var element = angular.compile('<input type="image" ng:click="action()">')($rootScope);
|
||||
var element = $compile('<input type="image" ng:click="action()">')($rootScope);
|
||||
$rootScope.action = function() {
|
||||
log += 'click;';
|
||||
};
|
||||
|
|
@ -123,9 +123,9 @@ describe('Binder', function() {
|
|||
expect(log).toEqual('click;');
|
||||
}));
|
||||
|
||||
it('ButtonElementActionExecutesInScope', inject(function($rootScope) {
|
||||
it('ButtonElementActionExecutesInScope', inject(function($rootScope, $compile) {
|
||||
var savedCalled = false;
|
||||
var element = angular.compile('<button ng:click="person.save()">Apply</button>')($rootScope);
|
||||
var element = $compile('<button ng:click="person.save()">Apply</button>')($rootScope);
|
||||
$rootScope.person = {};
|
||||
$rootScope.person.save = function() {
|
||||
savedCalled = true;
|
||||
|
|
@ -134,8 +134,8 @@ describe('Binder', function() {
|
|||
assertTrue(savedCalled);
|
||||
}));
|
||||
|
||||
it('RepeaterUpdateBindings', inject(function($rootScope) {
|
||||
var form = angular.compile(
|
||||
it('RepeaterUpdateBindings', inject(function($rootScope, $compile) {
|
||||
var form = $compile(
|
||||
'<ul>' +
|
||||
'<LI ng:repeat="item in model.items" ng:bind="item.a"></LI>' +
|
||||
'</ul>')($rootScope);
|
||||
|
|
@ -171,8 +171,8 @@ describe('Binder', function() {
|
|||
$rootScope.$apply();
|
||||
}));
|
||||
|
||||
it('RepeaterContentDoesNotBind', inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
it('RepeaterContentDoesNotBind', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
'<ul>' +
|
||||
'<LI ng:repeat="item in model.items"><span ng:bind="item.a"></span></li>' +
|
||||
'</ul>')($rootScope);
|
||||
|
|
@ -189,8 +189,8 @@ describe('Binder', function() {
|
|||
assertTrue(html.indexOf('action="foo();"') > 0 );
|
||||
});
|
||||
|
||||
it('RepeaterAdd', inject(function($rootScope) {
|
||||
var element = angular.compile('<div><input type="text" ng:model="item.x" ng:repeat="item in items"></div>')($rootScope);
|
||||
it('RepeaterAdd', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div><input type="text" ng:model="item.x" ng:repeat="item in items"></div>')($rootScope);
|
||||
$rootScope.items = [{x:'a'}, {x:'b'}];
|
||||
$rootScope.$apply();
|
||||
var first = childNode(element, 1);
|
||||
|
|
@ -204,8 +204,8 @@ describe('Binder', function() {
|
|||
expect($rootScope.items[0].x).toEqual('ABC');
|
||||
}));
|
||||
|
||||
it('ItShouldRemoveExtraChildrenWhenIteratingOverHash', inject(function($rootScope) {
|
||||
var element = angular.compile('<div><div ng:repeat="i in items">{{i}}</div></div>')($rootScope);
|
||||
it('ItShouldRemoveExtraChildrenWhenIteratingOverHash', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div><div ng:repeat="i in items">{{i}}</div></div>')($rootScope);
|
||||
var items = {};
|
||||
$rootScope.items = items;
|
||||
|
||||
|
|
@ -225,8 +225,8 @@ describe('Binder', function() {
|
|||
function(service){
|
||||
service('$exceptionHandler', $exceptionHandlerMockFactory);
|
||||
},
|
||||
function($rootScope, $exceptionHandler) {
|
||||
angular.compile('<div>{{error.throw()}}</div>', null, true)($rootScope);
|
||||
function($rootScope, $exceptionHandler, $compile) {
|
||||
$compile('<div>{{error.throw()}}</div>', null, true)($rootScope);
|
||||
var errorLogs = $exceptionHandler.errors;
|
||||
|
||||
$rootScope.error = {
|
||||
|
|
@ -247,8 +247,8 @@ describe('Binder', function() {
|
|||
|
||||
it('IfAttrBindingThrowsErrorDecorateTheAttribute', inject(function(service){
|
||||
service('$exceptionHandler', $exceptionHandlerMockFactory);
|
||||
}, function($rootScope, $exceptionHandler) {
|
||||
angular.compile('<div attr="before {{error.throw()}} after"></div>', null, true)($rootScope);
|
||||
}, function($rootScope, $exceptionHandler, $compile) {
|
||||
$compile('<div attr="before {{error.throw()}} after"></div>', null, true)($rootScope);
|
||||
var errorLogs = $exceptionHandler.errors;
|
||||
var count = 0;
|
||||
|
||||
|
|
@ -265,8 +265,8 @@ describe('Binder', function() {
|
|||
expect(errorLogs.length).toMatch(0);
|
||||
}));
|
||||
|
||||
it('NestedRepeater', inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
it('NestedRepeater', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
'<div>' +
|
||||
'<div ng:repeat="m in model" name="{{m.name}}">' +
|
||||
'<ul name="{{i}}" ng:repeat="i in m.item"></ul>' +
|
||||
|
|
@ -290,8 +290,8 @@ describe('Binder', function() {
|
|||
'</div></div>', sortedHtml(element));
|
||||
}));
|
||||
|
||||
it('HideBindingExpression', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:hide="hidden == 3"/>')($rootScope);
|
||||
it('HideBindingExpression', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:hide="hidden == 3"/>')($rootScope);
|
||||
|
||||
$rootScope.hidden = 3;
|
||||
$rootScope.$apply();
|
||||
|
|
@ -304,8 +304,8 @@ describe('Binder', function() {
|
|||
assertVisible(element);
|
||||
}));
|
||||
|
||||
it('HideBinding', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:hide="hidden"/>')($rootScope);
|
||||
it('HideBinding', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:hide="hidden"/>')($rootScope);
|
||||
|
||||
$rootScope.hidden = 'true';
|
||||
$rootScope.$apply();
|
||||
|
|
@ -323,8 +323,8 @@ describe('Binder', function() {
|
|||
assertVisible(element);
|
||||
}));
|
||||
|
||||
it('ShowBinding', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:show="show"/>')($rootScope);
|
||||
it('ShowBinding', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:show="show"/>')($rootScope);
|
||||
|
||||
$rootScope.show = 'true';
|
||||
$rootScope.$apply();
|
||||
|
|
@ -343,8 +343,8 @@ describe('Binder', function() {
|
|||
}));
|
||||
|
||||
|
||||
it('BindClass', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:class="clazz"/>')($rootScope);
|
||||
it('BindClass', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:class="clazz"/>')($rootScope);
|
||||
|
||||
$rootScope.clazz = 'testClass';
|
||||
$rootScope.$apply();
|
||||
|
|
@ -357,8 +357,8 @@ describe('Binder', function() {
|
|||
assertEquals('<div class="a b" ng:class="clazz"></div>', sortedHtml(element));
|
||||
}));
|
||||
|
||||
it('BindClassEvenOdd', inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
it('BindClassEvenOdd', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
'<div>' +
|
||||
'<div ng:repeat="i in [0,1]" ng:class-even="\'e\'" ng:class-odd="\'o\'"></div>' +
|
||||
'</div>')($rootScope);
|
||||
|
|
@ -374,8 +374,8 @@ describe('Binder', function() {
|
|||
sortedHtml(element));
|
||||
}));
|
||||
|
||||
it('BindStyle', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:style="style"/>')($rootScope);
|
||||
it('BindStyle', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:style="style"/>')($rootScope);
|
||||
|
||||
$rootScope.$eval('style={height: "10px"}');
|
||||
$rootScope.$apply();
|
||||
|
|
@ -390,8 +390,8 @@ describe('Binder', function() {
|
|||
function(service){
|
||||
service('$exceptionHandler', $exceptionHandlerMockFactory);
|
||||
},
|
||||
function($rootScope, $exceptionHandler) {
|
||||
var input = angular.compile('<a ng:click="action()">Add Phone</a>')($rootScope);
|
||||
function($rootScope, $exceptionHandler, $compile) {
|
||||
var input = $compile('<a ng:click="action()">Add Phone</a>')($rootScope);
|
||||
$rootScope.action = function() {
|
||||
throw new Error('MyError');
|
||||
};
|
||||
|
|
@ -400,8 +400,8 @@ describe('Binder', function() {
|
|||
})
|
||||
);
|
||||
|
||||
it('ShoulIgnoreVbNonBindable', inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
it('ShoulIgnoreVbNonBindable', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
"<div>{{a}}" +
|
||||
"<div ng:non-bindable>{{a}}</div>" +
|
||||
"<div ng:non-bindable=''>{{b}}</div>" +
|
||||
|
|
@ -412,8 +412,8 @@ describe('Binder', function() {
|
|||
assertEquals('123{{a}}{{b}}{{c}}', element.text());
|
||||
}));
|
||||
|
||||
it('ShouldTemplateBindPreElements', inject(function ($rootScope) {
|
||||
var element = angular.compile('<pre>Hello {{name}}!</pre>')($rootScope);
|
||||
it('ShouldTemplateBindPreElements', inject(function ($rootScope, $compile) {
|
||||
var element = $compile('<pre>Hello {{name}}!</pre>')($rootScope);
|
||||
$rootScope.name = "World";
|
||||
$rootScope.$apply();
|
||||
|
||||
|
|
@ -422,8 +422,8 @@ describe('Binder', function() {
|
|||
sortedHtml(element));
|
||||
}));
|
||||
|
||||
it('FillInOptionValueWhenMissing', inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
it('FillInOptionValueWhenMissing', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
'<select ng:model="foo">' +
|
||||
'<option selected="true">{{a}}</option>' +
|
||||
'<option value="">{{b}}</option>' +
|
||||
|
|
@ -446,8 +446,8 @@ describe('Binder', function() {
|
|||
expect(optionC.text()).toEqual('C');
|
||||
}));
|
||||
|
||||
it('DeleteAttributeIfEvaluatesFalse', inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
it('DeleteAttributeIfEvaluatesFalse', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
'<div>' +
|
||||
'<input ng:model="a0" ng:bind-attr="{disabled:\'{{true}}\'}">' +
|
||||
'<input ng:model="a1" ng:bind-attr="{disabled:\'{{false}}\'}">' +
|
||||
|
|
@ -474,8 +474,8 @@ describe('Binder', function() {
|
|||
function(service){
|
||||
service('$exceptionHandler', $exceptionHandlerMockFactory);
|
||||
},
|
||||
function($rootScope, $exceptionHandler, $log) {
|
||||
var element = angular.compile(
|
||||
function($rootScope, $exceptionHandler, $log, $compile) {
|
||||
var element = $compile(
|
||||
'<div>' +
|
||||
'<input type="button" ng:click="greeting=\'ABC\'"/>' +
|
||||
'<input type="button" ng:click=":garbage:"/>' +
|
||||
|
|
@ -494,8 +494,8 @@ describe('Binder', function() {
|
|||
})
|
||||
);
|
||||
|
||||
it('ItShouldSelectTheCorrectRadioBox', inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
it('ItShouldSelectTheCorrectRadioBox', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
'<div>' +
|
||||
'<input type="radio" ng:model="sex" value="female">' +
|
||||
'<input type="radio" ng:model="sex" value="male">' +
|
||||
|
|
@ -516,8 +516,8 @@ describe('Binder', function() {
|
|||
assertEquals("male", male.val());
|
||||
}));
|
||||
|
||||
it('ItShouldRepeatOnHashes', inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
it('ItShouldRepeatOnHashes', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
'<ul>' +
|
||||
'<li ng:repeat="(k,v) in {a:0,b:1}" ng:bind=\"k + v\"></li>' +
|
||||
'</ul>')($rootScope);
|
||||
|
|
@ -530,8 +530,8 @@ describe('Binder', function() {
|
|||
sortedHtml(element));
|
||||
}));
|
||||
|
||||
it('ItShouldFireChangeListenersBeforeUpdate', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:bind="name"></div>')($rootScope);
|
||||
it('ItShouldFireChangeListenersBeforeUpdate', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:bind="name"></div>')($rootScope);
|
||||
$rootScope.name = "";
|
||||
$rootScope.$watch("watched", "name=123");
|
||||
$rootScope.watched = "change";
|
||||
|
|
@ -542,8 +542,8 @@ describe('Binder', function() {
|
|||
sortedHtml(element));
|
||||
}));
|
||||
|
||||
it('ItShouldHandleMultilineBindings', inject(function($rootScope) {
|
||||
var element = angular.compile('<div>{{\n 1 \n + \n 2 \n}}</div>')($rootScope);
|
||||
it('ItShouldHandleMultilineBindings', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div>{{\n 1 \n + \n 2 \n}}</div>')($rootScope);
|
||||
$rootScope.$apply();
|
||||
assertEquals("3", element.text());
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -221,8 +221,8 @@ describe("resource", function() {
|
|||
nakedExpect(visa).toEqual({id:123});
|
||||
}));
|
||||
|
||||
it('should excersize full stack', inject(function($rootScope, $browser, $resource) {
|
||||
angular.compile('<div></div>')($rootScope);
|
||||
it('should excersize full stack', inject(function($rootScope, $browser, $resource, $compile) {
|
||||
$compile('<div></div>')($rootScope);
|
||||
var Person = $resource('/Person/:id');
|
||||
$browser.xhr.expectGET('/Person/123').respond('\n{\n"name":\n"misko"\n}\n');
|
||||
var person = Person.get({id:123});
|
||||
|
|
@ -230,8 +230,8 @@ describe("resource", function() {
|
|||
expect(person.name).toEqual('misko');
|
||||
}));
|
||||
|
||||
it('should return the same object when verifying the cache', inject(function($rootScope) {
|
||||
angular.compile('<div></div>')($rootScope);
|
||||
it('should return the same object when verifying the cache', inject(function($rootScope, $compile) {
|
||||
$compile('<div></div>')($rootScope);
|
||||
var $browser = $rootScope.$service('$browser');
|
||||
var $resource = $rootScope.$service('$resource');
|
||||
var Person = $resource('/Person/:id', null, {query: {method:'GET', isArray: true, verifyCache: true}});
|
||||
|
|
|
|||
|
|
@ -2,22 +2,22 @@
|
|||
|
||||
describe("ScenarioSpec: Compilation", function() {
|
||||
describe('compilation', function() {
|
||||
it("should compile dom node and return scope", inject(function($rootScope) {
|
||||
it("should compile dom node and return scope", inject(function($rootScope, $compile) {
|
||||
var node = jqLite('<div ng:init="a=1">{{b=a+1}}</div>')[0];
|
||||
angular.compile(node)($rootScope);
|
||||
$compile(node)($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect($rootScope.a).toEqual(1);
|
||||
expect($rootScope.b).toEqual(2);
|
||||
}));
|
||||
|
||||
it("should compile jQuery node and return scope", inject(function($rootScope) {
|
||||
var element = compile(jqLite('<div>{{a=123}}</div>'))($rootScope);
|
||||
it("should compile jQuery node and return scope", inject(function($rootScope, $compile) {
|
||||
var element = $compile(jqLite('<div>{{a=123}}</div>'))($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(jqLite(element).text()).toEqual('123');
|
||||
}));
|
||||
|
||||
it("should compile text node and return scope", inject(function($rootScope) {
|
||||
var element = angular.compile('<div>{{a=123}}</div>')($rootScope);
|
||||
it("should compile text node and return scope", inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div>{{a=123}}</div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(jqLite(element).text()).toEqual('123');
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
describe("directive", function() {
|
||||
|
||||
it("should ng:init", inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:init="a=123"></div>')($rootScope);
|
||||
it("should ng:init", inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:init="a=123"></div>')($rootScope);
|
||||
expect($rootScope.a).toEqual(123);
|
||||
}));
|
||||
|
||||
describe('ng:bind', function() {
|
||||
it('should set text', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:bind="a"></div>')($rootScope);
|
||||
it('should set text', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:bind="a"></div>')($rootScope);
|
||||
expect(element.text()).toEqual('');
|
||||
$rootScope.a = 'misko';
|
||||
$rootScope.$digest();
|
||||
|
|
@ -17,8 +17,8 @@ describe("directive", function() {
|
|||
expect(element.text()).toEqual('misko');
|
||||
}));
|
||||
|
||||
it('should set text to blank if undefined', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:bind="a"></div>')($rootScope);
|
||||
it('should set text to blank if undefined', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:bind="a"></div>')($rootScope);
|
||||
$rootScope.a = 'misko';
|
||||
$rootScope.$digest();
|
||||
expect(element.text()).toEqual('misko');
|
||||
|
|
@ -27,76 +27,76 @@ describe("directive", function() {
|
|||
expect(element.text()).toEqual('');
|
||||
}));
|
||||
|
||||
it('should set html', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:bind="html|html"></div>')($rootScope);
|
||||
it('should set html', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:bind="html|html"></div>')($rootScope);
|
||||
$rootScope.html = '<div unknown>hello</div>';
|
||||
$rootScope.$digest();
|
||||
expect(lowercase(element.html())).toEqual('<div>hello</div>');
|
||||
}));
|
||||
|
||||
it('should set unsafe html', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:bind="html|html:\'unsafe\'"></div>')($rootScope);
|
||||
it('should set unsafe html', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:bind="html|html:\'unsafe\'"></div>')($rootScope);
|
||||
$rootScope.html = '<div onclick="">hello</div>';
|
||||
$rootScope.$digest();
|
||||
expect(lowercase(element.html())).toEqual('<div onclick="">hello</div>');
|
||||
}));
|
||||
|
||||
it('should set element element', inject(function($rootScope) {
|
||||
it('should set element element', inject(function($rootScope, $compile) {
|
||||
angularFilter.myElement = function() {
|
||||
return jqLite('<a>hello</a>');
|
||||
};
|
||||
var element = angular.compile('<div ng:bind="0|myElement"></div>')($rootScope);
|
||||
var element = $compile('<div ng:bind="0|myElement"></div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(lowercase(element.html())).toEqual('<a>hello</a>');
|
||||
}));
|
||||
|
||||
it('should have $element set to current bind element', inject(function($rootScope) {
|
||||
it('should have $element set to current bind element', inject(function($rootScope, $compile) {
|
||||
angularFilter.myFilter = function() {
|
||||
this.$element.addClass("filter");
|
||||
return 'HELLO';
|
||||
};
|
||||
var element = angular.compile('<div>before<div ng:bind="0|myFilter"></div>after</div>')($rootScope);
|
||||
var element = $compile('<div>before<div ng:bind="0|myFilter"></div>after</div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(sortedHtml(element)).toEqual('<div>before<div class="filter" ng:bind="0|myFilter">HELLO</div>after</div>');
|
||||
}));
|
||||
|
||||
|
||||
it('should suppress rendering of falsy values', inject(function($rootScope) {
|
||||
var element = angular.compile('<div>{{ null }}{{ undefined }}{{ "" }}-{{ 0 }}{{ false }}</div>')($rootScope);
|
||||
it('should suppress rendering of falsy values', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div>{{ null }}{{ undefined }}{{ "" }}-{{ 0 }}{{ false }}</div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(element.text()).toEqual('-0false');
|
||||
}));
|
||||
|
||||
it('should render object as JSON ignore $$', inject(function($rootScope) {
|
||||
var element = angular.compile('<div>{{ {key:"value", $$key:"hide"} }}</div>')($rootScope);
|
||||
it('should render object as JSON ignore $$', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div>{{ {key:"value", $$key:"hide"} }}</div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(fromJson(element.text())).toEqual({key:'value'});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('ng:bind-template', function() {
|
||||
it('should ng:bind-template', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:bind-template="Hello {{name}}!"></div>')($rootScope);
|
||||
it('should ng:bind-template', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:bind-template="Hello {{name}}!"></div>')($rootScope);
|
||||
$rootScope.name = 'Misko';
|
||||
$rootScope.$digest();
|
||||
expect(element.hasClass('ng-binding')).toEqual(true);
|
||||
expect(element.text()).toEqual('Hello Misko!');
|
||||
}));
|
||||
|
||||
it('should have $element set to current bind element', inject(function($rootScope) {
|
||||
it('should have $element set to current bind element', inject(function($rootScope, $compile) {
|
||||
var innerText;
|
||||
angularFilter.myFilter = function(text) {
|
||||
innerText = innerText || this.$element.text();
|
||||
return text;
|
||||
};
|
||||
var element = angular.compile('<div>before<span ng:bind-template="{{\'HELLO\'|myFilter}}">INNER</span>after</div>')($rootScope);
|
||||
var element = $compile('<div>before<span ng:bind-template="{{\'HELLO\'|myFilter}}">INNER</span>after</div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(element.text()).toEqual("beforeHELLOafter");
|
||||
expect(innerText).toEqual('INNER');
|
||||
}));
|
||||
|
||||
it('should render object as JSON ignore $$', inject(function($rootScope) {
|
||||
var element = angular.compile('<pre>{{ {key:"value", $$key:"hide"} }}</pre>')($rootScope);
|
||||
it('should render object as JSON ignore $$', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<pre>{{ {key:"value", $$key:"hide"} }}</pre>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(fromJson(element.text())).toEqual({key:'value'});
|
||||
}));
|
||||
|
|
@ -104,22 +104,22 @@ describe("directive", function() {
|
|||
});
|
||||
|
||||
describe('ng:bind-attr', function() {
|
||||
it('should bind attributes', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:bind-attr="{src:\'http://localhost/mysrc\', alt:\'myalt\'}"/>')($rootScope);
|
||||
it('should bind attributes', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:bind-attr="{src:\'http://localhost/mysrc\', alt:\'myalt\'}"/>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(element.attr('src')).toEqual('http://localhost/mysrc');
|
||||
expect(element.attr('alt')).toEqual('myalt');
|
||||
}));
|
||||
|
||||
it('should not pretty print JSON in attributes', inject(function($rootScope) {
|
||||
var element = angular.compile('<img alt="{{ {a:1} }}"/>')($rootScope);
|
||||
it('should not pretty print JSON in attributes', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<img alt="{{ {a:1} }}"/>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(element.attr('alt')).toEqual('{"a":1}');
|
||||
}));
|
||||
});
|
||||
|
||||
it('should remove special attributes on false', inject(function($rootScope) {
|
||||
var element = angular.compile('<input ng:bind-attr="{disabled:\'{{disabled}}\', readonly:\'{{readonly}}\', checked:\'{{checked}}\'}"/>')($rootScope);
|
||||
it('should remove special attributes on false', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<input ng:bind-attr="{disabled:\'{{disabled}}\', readonly:\'{{readonly}}\', checked:\'{{checked}}\'}"/>')($rootScope);
|
||||
var input = element[0];
|
||||
expect(input.disabled).toEqual(false);
|
||||
expect(input.readOnly).toEqual(false);
|
||||
|
|
@ -136,8 +136,8 @@ describe("directive", function() {
|
|||
}));
|
||||
|
||||
describe('ng:click', function() {
|
||||
it('should get called on a click', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:click="clicked = true"></div>')($rootScope);
|
||||
it('should get called on a click', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:click="clicked = true"></div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect($rootScope.clicked).toBeFalsy();
|
||||
|
||||
|
|
@ -145,8 +145,8 @@ describe("directive", function() {
|
|||
expect($rootScope.clicked).toEqual(true);
|
||||
}));
|
||||
|
||||
it('should stop event propagation', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:click="outer = true"><div ng:click="inner = true"></div></div>')($rootScope);
|
||||
it('should stop event propagation', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:click="outer = true"><div ng:click="inner = true"></div></div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect($rootScope.outer).not.toBeDefined();
|
||||
expect($rootScope.inner).not.toBeDefined();
|
||||
|
|
@ -161,8 +161,8 @@ describe("directive", function() {
|
|||
|
||||
|
||||
describe('ng:submit', function() {
|
||||
it('should get called on form submit', inject(function($rootScope) {
|
||||
var element = angular.compile('<form action="" ng:submit="submitted = true">' +
|
||||
it('should get called on form submit', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<form action="" ng:submit="submitted = true">' +
|
||||
'<input type="submit"/>' +
|
||||
'</form>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
|
|
@ -174,8 +174,8 @@ describe("directive", function() {
|
|||
});
|
||||
|
||||
describe('ng:class', function() {
|
||||
it('should add new and remove old classes dynamically', inject(function($rootScope) {
|
||||
var element = angular.compile('<div class="existing" ng:class="dynClass"></div>')($rootScope);
|
||||
it('should add new and remove old classes dynamically', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div class="existing" ng:class="dynClass"></div>')($rootScope);
|
||||
$rootScope.dynClass = 'A';
|
||||
$rootScope.$digest();
|
||||
expect(element.hasClass('existing')).toBe(true);
|
||||
|
|
@ -195,8 +195,8 @@ describe("directive", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should support adding multiple classes via an array', inject(function($rootScope) {
|
||||
var element = angular.compile('<div class="existing" ng:class="[\'A\', \'B\']"></div>')($rootScope);
|
||||
it('should support adding multiple classes via an array', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div class="existing" ng:class="[\'A\', \'B\']"></div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(element.hasClass('existing')).toBeTruthy();
|
||||
expect(element.hasClass('A')).toBeTruthy();
|
||||
|
|
@ -204,8 +204,8 @@ describe("directive", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should support adding multiple classes via a space delimited string', inject(function($rootScope) {
|
||||
var element = angular.compile('<div class="existing" ng:class="\'A B\'"></div>')($rootScope);
|
||||
it('should support adding multiple classes via a space delimited string', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div class="existing" ng:class="\'A B\'"></div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(element.hasClass('existing')).toBeTruthy();
|
||||
expect(element.hasClass('A')).toBeTruthy();
|
||||
|
|
@ -213,8 +213,8 @@ describe("directive", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should preserve class added post compilation with pre-existing classes', inject(function($rootScope) {
|
||||
var element = angular.compile('<div class="existing" ng:class="dynClass"></div>')($rootScope);
|
||||
it('should preserve class added post compilation with pre-existing classes', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div class="existing" ng:class="dynClass"></div>')($rootScope);
|
||||
$rootScope.dynClass = 'A';
|
||||
$rootScope.$digest();
|
||||
expect(element.hasClass('existing')).toBe(true);
|
||||
|
|
@ -230,8 +230,8 @@ describe("directive", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should preserve class added post compilation without pre-existing classes"', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:class="dynClass"></div>')($rootScope);
|
||||
it('should preserve class added post compilation without pre-existing classes"', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:class="dynClass"></div>')($rootScope);
|
||||
$rootScope.dynClass = 'A';
|
||||
$rootScope.$digest();
|
||||
expect(element.hasClass('A')).toBe(true);
|
||||
|
|
@ -246,8 +246,8 @@ describe("directive", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should preserve other classes with similar name"', inject(function($rootScope) {
|
||||
var element = angular.compile('<div class="ui-panel ui-selected" ng:class="dynCls"></div>')($rootScope);
|
||||
it('should preserve other classes with similar name"', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div class="ui-panel ui-selected" ng:class="dynCls"></div>')($rootScope);
|
||||
$rootScope.dynCls = 'panel';
|
||||
$rootScope.$digest();
|
||||
$rootScope.dynCls = 'foo';
|
||||
|
|
@ -256,16 +256,16 @@ describe("directive", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should not add duplicate classes', inject(function($rootScope) {
|
||||
var element = angular.compile('<div class="panel bar" ng:class="dynCls"></div>')($rootScope);
|
||||
it('should not add duplicate classes', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div class="panel bar" ng:class="dynCls"></div>')($rootScope);
|
||||
$rootScope.dynCls = 'panel';
|
||||
$rootScope.$digest();
|
||||
expect(element[0].className).toBe('panel bar ng-directive');
|
||||
}));
|
||||
|
||||
|
||||
it('should remove classes even if it was specified via class attribute', inject(function($rootScope) {
|
||||
var element = angular.compile('<div class="panel bar" ng:class="dynCls"></div>')($rootScope);
|
||||
it('should remove classes even if it was specified via class attribute', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div class="panel bar" ng:class="dynCls"></div>')($rootScope);
|
||||
$rootScope.dynCls = 'panel';
|
||||
$rootScope.$digest();
|
||||
$rootScope.dynCls = 'window';
|
||||
|
|
@ -274,8 +274,8 @@ describe("directive", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should remove classes even if they were added by another code', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:class="dynCls"></div>')($rootScope);
|
||||
it('should remove classes even if they were added by another code', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:class="dynCls"></div>')($rootScope);
|
||||
$rootScope.dynCls = 'foo';
|
||||
$rootScope.$digest();
|
||||
element.addClass('foo');
|
||||
|
|
@ -285,8 +285,8 @@ describe("directive", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should convert undefined and null values to an empty string', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:class="dynCls"></div>')($rootScope);
|
||||
it('should convert undefined and null values to an empty string', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:class="dynCls"></div>')($rootScope);
|
||||
$rootScope.dynCls = [undefined, null];
|
||||
$rootScope.$digest();
|
||||
expect(element[0].className).toBe('ng-directive');
|
||||
|
|
@ -294,8 +294,8 @@ describe("directive", function() {
|
|||
});
|
||||
|
||||
|
||||
it('should ng:class odd/even', inject(function($rootScope) {
|
||||
var element = angular.compile('<ul><li ng:repeat="i in [0,1]" class="existing" ng:class-odd="\'odd\'" ng:class-even="\'even\'"></li><ul>')($rootScope);
|
||||
it('should ng:class odd/even', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<ul><li ng:repeat="i in [0,1]" class="existing" ng:class-odd="\'odd\'" ng:class-even="\'even\'"></li><ul>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
var e1 = jqLite(element[0].childNodes[1]);
|
||||
var e2 = jqLite(element[0].childNodes[2]);
|
||||
|
|
@ -306,8 +306,8 @@ describe("directive", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should allow both ng:class and ng:class-odd/even on the same element', inject(function($rootScope) {
|
||||
var element = angular.compile('<ul>' +
|
||||
it('should allow both ng:class and ng:class-odd/even on the same element', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<ul>' +
|
||||
'<li ng:repeat="i in [0,1]" ng:class="\'plainClass\'" ' +
|
||||
'ng:class-odd="\'odd\'" ng:class-even="\'even\'"></li>' +
|
||||
'<ul>')($rootScope);
|
||||
|
|
@ -324,8 +324,8 @@ describe("directive", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should allow both ng:class and ng:class-odd/even with multiple classes', inject(function($rootScope) {
|
||||
var element = angular.compile('<ul>' +
|
||||
it('should allow both ng:class and ng:class-odd/even with multiple classes', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<ul>' +
|
||||
'<li ng:repeat="i in [0,1]" ng:class="[\'A\', \'B\']" ' +
|
||||
'ng:class-odd="[\'C\', \'D\']" ng:class-even="[\'E\', \'F\']"></li>' +
|
||||
'<ul>')($rootScope);
|
||||
|
|
@ -351,15 +351,15 @@ describe("directive", function() {
|
|||
|
||||
describe('ng:style', function() {
|
||||
|
||||
it('should set', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:style="{height: \'40px\'}"></div>')($rootScope);
|
||||
it('should set', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:style="{height: \'40px\'}"></div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(element.css('height')).toEqual('40px');
|
||||
}));
|
||||
|
||||
|
||||
it('should silently ignore undefined style', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:style="myStyle"></div>')($rootScope);
|
||||
it('should silently ignore undefined style', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:style="myStyle"></div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(element.hasClass('ng-exception')).toBeFalsy();
|
||||
}));
|
||||
|
|
@ -368,7 +368,7 @@ describe("directive", function() {
|
|||
describe('preserving styles set before and after compilation', function() {
|
||||
var scope, preCompStyle, preCompVal, postCompStyle, postCompVal, element;
|
||||
|
||||
beforeEach(inject(function($rootScope) {
|
||||
beforeEach(inject(function($rootScope, $compile) {
|
||||
preCompStyle = 'width';
|
||||
preCompVal = '300px';
|
||||
postCompStyle = 'height';
|
||||
|
|
@ -376,7 +376,7 @@ describe("directive", function() {
|
|||
element = jqLite('<div ng:style="styleObj"></div>');
|
||||
element.css(preCompStyle, preCompVal);
|
||||
jqLite(document.body).append(element);
|
||||
angular.compile(element)($rootScope);
|
||||
$compile(element)($rootScope);
|
||||
scope = $rootScope;
|
||||
scope.styleObj = {'margin-top': '44px'};
|
||||
scope.$apply();
|
||||
|
|
@ -431,9 +431,9 @@ describe("directive", function() {
|
|||
|
||||
|
||||
describe('ng:show', function() {
|
||||
it('should show and hide an element', inject(function($rootScope) {
|
||||
it('should show and hide an element', inject(function($rootScope, $compile) {
|
||||
var element = jqLite('<div ng:show="exp"></div>');
|
||||
var element = angular.compile(element)($rootScope);
|
||||
var element = $compile(element)($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(isCssVisible(element)).toEqual(false);
|
||||
$rootScope.exp = true;
|
||||
|
|
@ -442,9 +442,9 @@ describe("directive", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should make hidden element visible', inject(function($rootScope) {
|
||||
it('should make hidden element visible', inject(function($rootScope, $compile) {
|
||||
var element = jqLite('<div style="display: none" ng:show="exp"></div>');
|
||||
var element = angular.compile(element)($rootScope);
|
||||
var element = $compile(element)($rootScope);
|
||||
expect(isCssVisible(element)).toBe(false);
|
||||
$rootScope.exp = true;
|
||||
$rootScope.$digest();
|
||||
|
|
@ -453,9 +453,9 @@ describe("directive", function() {
|
|||
});
|
||||
|
||||
describe('ng:hide', function() {
|
||||
it('should hide an element', inject(function($rootScope) {
|
||||
it('should hide an element', inject(function($rootScope, $compile) {
|
||||
var element = jqLite('<div ng:hide="exp"></div>');
|
||||
var element = angular.compile(element)($rootScope);
|
||||
var element = $compile(element)($rootScope);
|
||||
expect(isCssVisible(element)).toBe(true);
|
||||
$rootScope.exp = true;
|
||||
$rootScope.$digest();
|
||||
|
|
@ -485,13 +485,13 @@ describe("directive", function() {
|
|||
window.temp = undefined;
|
||||
});
|
||||
|
||||
it('should bind', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:controller="temp.Greeter"></div>')($rootScope);
|
||||
it('should bind', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:controller="temp.Greeter"></div>')($rootScope);
|
||||
expect($rootScope.greeter.greeting).toEqual('hello');
|
||||
expect($rootScope.greeter.greet('misko')).toEqual('hello misko!');
|
||||
}));
|
||||
|
||||
it('should support nested controllers', inject(function($rootScope) {
|
||||
it('should support nested controllers', inject(function($rootScope, $compile) {
|
||||
temp.ChildGreeter = function() {
|
||||
this.greeting = 'hey';
|
||||
this.$root.childGreeter = this;
|
||||
|
|
@ -501,7 +501,7 @@ describe("directive", function() {
|
|||
return this.greeting + ' dude' + this.suffix;
|
||||
}
|
||||
};
|
||||
var element = angular.compile('<div ng:controller="temp.Greeter"><div ng:controller="temp.ChildGreeter">{{greet("misko")}}</div></div>')($rootScope);
|
||||
var element = $compile('<div ng:controller="temp.Greeter"><div ng:controller="temp.ChildGreeter">{{greet("misko")}}</div></div>')($rootScope);
|
||||
expect($rootScope.greeting).not.toBeDefined();
|
||||
expect($rootScope.greeter.greeting).toEqual('hello');
|
||||
expect($rootScope.greeter.greet('misko')).toEqual('hello misko!');
|
||||
|
|
@ -512,33 +512,33 @@ describe("directive", function() {
|
|||
expect(element.text()).toEqual('hey dude!');
|
||||
}));
|
||||
|
||||
it('should infer injection arguments', inject(function($rootScope) {
|
||||
it('should infer injection arguments', inject(function($rootScope, $compile) {
|
||||
temp.MyController = function($xhr){
|
||||
this.$root.someService = $xhr;
|
||||
};
|
||||
var element = angular.compile('<div ng:controller="temp.MyController"></div>')($rootScope);
|
||||
var element = $compile('<div ng:controller="temp.MyController"></div>')($rootScope);
|
||||
expect($rootScope.someService).toBe($rootScope.$service('$xhr'));
|
||||
}));
|
||||
});
|
||||
|
||||
describe('ng:cloak', function() {
|
||||
|
||||
it('should get removed when an element is compiled', inject(function($rootScope) {
|
||||
it('should get removed when an element is compiled', inject(function($rootScope, $compile) {
|
||||
var element = jqLite('<div ng:cloak></div>');
|
||||
expect(element.attr('ng:cloak')).toBe('');
|
||||
angular.compile(element);
|
||||
$compile(element);
|
||||
expect(element.attr('ng:cloak')).toBeUndefined();
|
||||
}));
|
||||
|
||||
|
||||
it('should remove ng-cloak class from a compiled element', inject(function($rootScope) {
|
||||
it('should remove ng-cloak class from a compiled element', inject(function($rootScope, $compile) {
|
||||
var element = jqLite('<div ng:cloak class="foo ng-cloak bar"></div>');
|
||||
|
||||
expect(element.hasClass('foo')).toBe(true);
|
||||
expect(element.hasClass('ng-cloak')).toBe(true);
|
||||
expect(element.hasClass('bar')).toBe(true);
|
||||
|
||||
angular.compile(element);
|
||||
$compile(element);
|
||||
|
||||
expect(element.hasClass('foo')).toBe(true);
|
||||
expect(element.hasClass('ng-cloak')).toBe(false);
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
describe("markups", function() {
|
||||
|
||||
it('should translate {{}} in text', inject(function($rootScope) {
|
||||
var element = angular.compile('<div>hello {{name}}!</div>')($rootScope)
|
||||
it('should translate {{}} in text', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div>hello {{name}}!</div>')($rootScope)
|
||||
expect(sortedHtml(element)).toEqual('<div>hello <span ng:bind="name"></span>!</div>');
|
||||
$rootScope.name = 'Misko';
|
||||
$rootScope.$digest();
|
||||
expect(sortedHtml(element)).toEqual('<div>hello <span ng:bind="name">Misko</span>!</div>');
|
||||
}));
|
||||
|
||||
it('should translate {{}} in terminal nodes', inject(function($rootScope) {
|
||||
var element = angular.compile('<select ng:model="x"><option value="">Greet {{name}}!</option></select>')($rootScope)
|
||||
it('should translate {{}} in terminal nodes', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<select ng:model="x"><option value="">Greet {{name}}!</option></select>')($rootScope)
|
||||
$rootScope.$digest();
|
||||
expect(sortedHtml(element).replace(' selected="true"', '')).
|
||||
toEqual('<select ng:model="x">' +
|
||||
|
|
@ -25,8 +25,8 @@ describe("markups", function() {
|
|||
'</select>');
|
||||
}));
|
||||
|
||||
it('should translate {{}} in attributes', inject(function($rootScope) {
|
||||
var element = angular.compile('<div src="http://server/{{path}}.png"/>')($rootScope)
|
||||
it('should translate {{}} in attributes', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div src="http://server/{{path}}.png"/>')($rootScope)
|
||||
expect(element.attr('ng:bind-attr')).toEqual('{"src":"http://server/{{path}}.png"}');
|
||||
$rootScope.path = 'a/b';
|
||||
$rootScope.$digest();
|
||||
|
|
@ -55,37 +55,37 @@ describe("markups", function() {
|
|||
});
|
||||
|
||||
|
||||
it('should populate value attribute on OPTION', inject(function($rootScope) {
|
||||
var element = angular.compile('<select ng:model="x"><option>abc</option></select>')($rootScope)
|
||||
it('should populate value attribute on OPTION', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<select ng:model="x"><option>abc</option></select>')($rootScope)
|
||||
expect(element).toHaveValue('abc');
|
||||
}));
|
||||
|
||||
it('should ignore value if already exists', inject(function($rootScope) {
|
||||
var element = angular.compile('<select ng:model="x"><option value="abc">xyz</option></select>')($rootScope)
|
||||
it('should ignore value if already exists', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<select ng:model="x"><option value="abc">xyz</option></select>')($rootScope)
|
||||
expect(element).toHaveValue('abc');
|
||||
}));
|
||||
|
||||
it('should set value even if newlines present', inject(function($rootScope) {
|
||||
var element = angular.compile('<select ng:model="x"><option attr="\ntext\n" \n>\nabc\n</option></select>')($rootScope)
|
||||
it('should set value even if newlines present', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<select ng:model="x"><option attr="\ntext\n" \n>\nabc\n</option></select>')($rootScope)
|
||||
expect(element).toHaveValue('\nabc\n');
|
||||
}));
|
||||
|
||||
it('should set value even if self closing HTML', inject(function($rootScope) {
|
||||
it('should set value even if self closing HTML', inject(function($rootScope, $compile) {
|
||||
// IE removes the \n from option, which makes this test pointless
|
||||
if (msie) return;
|
||||
var element = angular.compile('<select ng:model="x"><option>\n</option></select>')($rootScope)
|
||||
var element = $compile('<select ng:model="x"><option>\n</option></select>')($rootScope)
|
||||
expect(element).toHaveValue('\n');
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
it('should bind href', inject(function($rootScope) {
|
||||
var element = angular.compile('<a ng:href="{{url}}"></a>')($rootScope)
|
||||
it('should bind href', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<a ng:href="{{url}}"></a>')($rootScope)
|
||||
expect(sortedHtml(element)).toEqual('<a ng:bind-attr="{"href":"{{url}}"}"></a>');
|
||||
}));
|
||||
|
||||
it('should bind disabled', inject(function($rootScope) {
|
||||
var element = angular.compile('<button ng:disabled="{{isDisabled}}">Button</button>')($rootScope)
|
||||
it('should bind disabled', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<button ng:disabled="{{isDisabled}}">Button</button>')($rootScope)
|
||||
$rootScope.isDisabled = false;
|
||||
$rootScope.$digest();
|
||||
expect(element.attr('disabled')).toBeFalsy();
|
||||
|
|
@ -94,8 +94,8 @@ describe("markups", function() {
|
|||
expect(element.attr('disabled')).toBeTruthy();
|
||||
}));
|
||||
|
||||
it('should bind checked', inject(function($rootScope) {
|
||||
var element = angular.compile('<input type="checkbox" ng:checked="{{isChecked}}" />')($rootScope)
|
||||
it('should bind checked', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<input type="checkbox" ng:checked="{{isChecked}}" />')($rootScope)
|
||||
$rootScope.isChecked = false;
|
||||
$rootScope.$digest();
|
||||
expect(element.attr('checked')).toBeFalsy();
|
||||
|
|
@ -104,8 +104,8 @@ describe("markups", function() {
|
|||
expect(element.attr('checked')).toBeTruthy();
|
||||
}));
|
||||
|
||||
it('should bind selected', inject(function($rootScope) {
|
||||
var element = angular.compile('<select><option value=""></option><option ng:selected="{{isSelected}}">Greetings!</option></select>')($rootScope)
|
||||
it('should bind selected', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<select><option value=""></option><option ng:selected="{{isSelected}}">Greetings!</option></select>')($rootScope)
|
||||
jqLite(document.body).append(element)
|
||||
$rootScope.isSelected=false;
|
||||
$rootScope.$digest();
|
||||
|
|
@ -115,8 +115,8 @@ describe("markups", function() {
|
|||
expect(element.children()[1].selected).toBeTruthy();
|
||||
}));
|
||||
|
||||
it('should bind readonly', inject(function($rootScope) {
|
||||
var element = angular.compile('<input type="text" ng:readonly="{{isReadonly}}" />')($rootScope)
|
||||
it('should bind readonly', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<input type="text" ng:readonly="{{isReadonly}}" />')($rootScope)
|
||||
$rootScope.isReadonly=false;
|
||||
$rootScope.$digest();
|
||||
expect(element.attr('readOnly')).toBeFalsy();
|
||||
|
|
@ -125,8 +125,8 @@ describe("markups", function() {
|
|||
expect(element.attr('readOnly')).toBeTruthy();
|
||||
}));
|
||||
|
||||
it('should bind multiple', inject(function($rootScope) {
|
||||
var element = angular.compile('<select ng:multiple="{{isMultiple}}"></select>')($rootScope)
|
||||
it('should bind multiple', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<select ng:multiple="{{isMultiple}}"></select>')($rootScope)
|
||||
$rootScope.isMultiple=false;
|
||||
$rootScope.$digest();
|
||||
expect(element.attr('multiple')).toBeFalsy();
|
||||
|
|
@ -135,57 +135,57 @@ describe("markups", function() {
|
|||
expect(element.attr('multiple')).toBeTruthy();
|
||||
}));
|
||||
|
||||
it('should bind src', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:src="{{url}}" />')($rootScope)
|
||||
it('should bind src', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:src="{{url}}" />')($rootScope)
|
||||
$rootScope.url = 'http://localhost/';
|
||||
$rootScope.$digest();
|
||||
expect(element.attr('src')).toEqual('http://localhost/');
|
||||
}));
|
||||
|
||||
it('should bind href and merge with other attrs', inject(function($rootScope) {
|
||||
var element = angular.compile('<a ng:href="{{url}}" rel="{{rel}}"></a>')($rootScope)
|
||||
it('should bind href and merge with other attrs', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<a ng:href="{{url}}" rel="{{rel}}"></a>')($rootScope)
|
||||
expect(sortedHtml(element)).toEqual('<a ng:bind-attr="{"href":"{{url}}","rel":"{{rel}}"}"></a>');
|
||||
}));
|
||||
|
||||
it('should bind Text with no Bindings', inject(function() {
|
||||
it('should bind Text with no Bindings', inject(function($compile) {
|
||||
var $rootScope;
|
||||
function newScope (){
|
||||
return $rootScope = angular.injector()('$rootScope');
|
||||
}
|
||||
forEach(['checked', 'disabled', 'multiple', 'readonly', 'selected'], function(name) {
|
||||
var element = angular.compile('<div ng:' + name + '="some"></div>')(newScope())
|
||||
var element = $compile('<div ng:' + name + '="some"></div>')(newScope())
|
||||
expect(element.attr('ng:bind-attr')).toBe('{"' + name +'":"some"}');
|
||||
$rootScope.$digest();
|
||||
expect(element.attr(name)).toBe(name);
|
||||
dealoc(element);
|
||||
});
|
||||
|
||||
var element = angular.compile('<div ng:src="some"></div>')(newScope())
|
||||
var element = $compile('<div ng:src="some"></div>')(newScope())
|
||||
$rootScope.$digest();
|
||||
expect(sortedHtml(element)).toEqual('<div ng:bind-attr="{"src":"some"}" src="some"></div>');
|
||||
dealoc(element);
|
||||
|
||||
var element = angular.compile('<div ng:href="some"></div>')(newScope())
|
||||
var element = $compile('<div ng:href="some"></div>')(newScope())
|
||||
$rootScope.$digest();
|
||||
expect(sortedHtml(element)).toEqual('<div href="some" ng:bind-attr="{"href":"some"}"></div>');
|
||||
dealoc(element);
|
||||
}));
|
||||
|
||||
it('should Parse Text With No Bindings', inject(function($rootScope) {
|
||||
it('should Parse Text With No Bindings', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings("a");
|
||||
assertEquals(parts.length, 1);
|
||||
assertEquals(parts[0], "a");
|
||||
assertTrue(!binding(parts[0]));
|
||||
}));
|
||||
|
||||
it('should Parse Empty Text', inject(function($rootScope) {
|
||||
it('should Parse Empty Text', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings("");
|
||||
assertEquals(parts.length, 1);
|
||||
assertEquals(parts[0], "");
|
||||
assertTrue(!binding(parts[0]));
|
||||
}));
|
||||
|
||||
it('should Parse Inner Binding', inject(function($rootScope) {
|
||||
it('should Parse Inner Binding', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings("a{{b}}C");
|
||||
assertEquals(parts.length, 3);
|
||||
assertEquals(parts[0], "a");
|
||||
|
|
@ -196,7 +196,7 @@ describe("markups", function() {
|
|||
assertTrue(!binding(parts[2]));
|
||||
}));
|
||||
|
||||
it('should Parse Ending Binding', inject(function($rootScope) {
|
||||
it('should Parse Ending Binding', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings("a{{b}}");
|
||||
assertEquals(parts.length, 2);
|
||||
assertEquals(parts[0], "a");
|
||||
|
|
@ -205,7 +205,7 @@ describe("markups", function() {
|
|||
assertEquals(binding(parts[1]), "b");
|
||||
}));
|
||||
|
||||
it('should Parse Begging Binding', inject(function($rootScope) {
|
||||
it('should Parse Begging Binding', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings("{{b}}c");
|
||||
assertEquals(parts.length, 2);
|
||||
assertEquals(parts[0], "{{b}}");
|
||||
|
|
@ -214,14 +214,14 @@ describe("markups", function() {
|
|||
assertTrue(!binding(parts[1]));
|
||||
}));
|
||||
|
||||
it('should Parse Loan Binding', inject(function($rootScope) {
|
||||
it('should Parse Loan Binding', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings("{{b}}");
|
||||
assertEquals(parts.length, 1);
|
||||
assertEquals(parts[0], "{{b}}");
|
||||
assertEquals(binding(parts[0]), "b");
|
||||
}));
|
||||
|
||||
it('should Parse Two Bindings', inject(function($rootScope) {
|
||||
it('should Parse Two Bindings', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings("{{b}}{{c}}");
|
||||
assertEquals(parts.length, 2);
|
||||
assertEquals(parts[0], "{{b}}");
|
||||
|
|
@ -230,7 +230,7 @@ describe("markups", function() {
|
|||
assertEquals(binding(parts[1]), "c");
|
||||
}));
|
||||
|
||||
it('should Parse Two Bindings With Text In Middle', inject(function($rootScope) {
|
||||
it('should Parse Two Bindings With Text In Middle', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings("{{b}}x{{c}}");
|
||||
assertEquals(parts.length, 3);
|
||||
assertEquals(parts[0], "{{b}}");
|
||||
|
|
@ -241,7 +241,7 @@ describe("markups", function() {
|
|||
assertEquals(binding(parts[2]), "c");
|
||||
}));
|
||||
|
||||
it('should Parse Multiline', inject(function($rootScope) {
|
||||
it('should Parse Multiline', inject(function($rootScope, $compile) {
|
||||
var parts = parseBindings('"X\nY{{A\nB}}C\nD"');
|
||||
assertTrue(!!binding('{{A\nB}}'));
|
||||
assertEquals(parts.length, 3);
|
||||
|
|
@ -250,7 +250,7 @@ describe("markups", function() {
|
|||
assertEquals(parts[2], 'C\nD"');
|
||||
}));
|
||||
|
||||
it('should Has Binding', inject(function($rootScope) {
|
||||
it('should Has Binding', inject(function($rootScope, $compile) {
|
||||
assertTrue(hasBindings(parseBindings("{{a}}")));
|
||||
assertTrue(!hasBindings(parseBindings("a")));
|
||||
assertTrue(hasBindings(parseBindings("{{b}}x{{c}}")));
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
describe('compiler', function() {
|
||||
var compiler, markup, attrMarkup, directives, widgets, compile, log, scope;
|
||||
var compiler, textMmarkup, attrMarkup, directives, widgets, compile, log, $rootScope;
|
||||
|
||||
beforeEach(inject(function($rootScope) {
|
||||
log = "";
|
||||
beforeEach(inject(function(service){
|
||||
textMmarkup = [];
|
||||
attrMarkup = [];
|
||||
widgets = extensionMap({}, 'widget');
|
||||
directives = {
|
||||
hello: function(expression, element){
|
||||
log += "hello ";
|
||||
|
|
@ -23,29 +25,25 @@ describe('compiler', function() {
|
|||
}
|
||||
|
||||
};
|
||||
markup = [];
|
||||
attrMarkup = [];
|
||||
widgets = extensionMap({}, 'widget');
|
||||
compiler = new Compiler(markup, attrMarkup, directives, widgets);
|
||||
compile = function(html){
|
||||
var e = jqLite("<div>" + html + "</div>");
|
||||
compiler.compile(e)($rootScope);
|
||||
return scope = $rootScope;
|
||||
};
|
||||
log = "";
|
||||
service('$textMarkup', valueFn(textMmarkup));
|
||||
service('$attrMarkup', valueFn(attrMarkup));
|
||||
service('$directive', valueFn(directives));
|
||||
service('$widget', valueFn(widgets));
|
||||
}));
|
||||
|
||||
|
||||
it('should not allow compilation of multiple roots', function() {
|
||||
it('should not allow compilation of multiple roots', inject(function($rootScope, $compile) {
|
||||
expect(function() {
|
||||
compiler.compile('<div>A</div><span></span>');
|
||||
$compile('<div>A</div><span></span>');
|
||||
}).toThrow("Cannot compile multiple element roots: " + ie("<div>A</div><span></span>"));
|
||||
function ie(text) {
|
||||
return msie < 9 ? uppercase(text) : text;
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
it('should recognize a directive', inject(function($rootScope) {
|
||||
it('should recognize a directive', inject(function($rootScope, $compile) {
|
||||
var e = jqLite('<div directive="expr" ignore="me"></div>');
|
||||
directives.directive = function(expression, element){
|
||||
log += "found";
|
||||
|
|
@ -55,42 +53,42 @@ describe('compiler', function() {
|
|||
log += ":init";
|
||||
};
|
||||
};
|
||||
var template = compiler.compile(e);
|
||||
var linkFn = $compile(e);
|
||||
expect(log).toEqual("found");
|
||||
scope = template($rootScope);
|
||||
linkFn($rootScope);
|
||||
expect(e.hasClass('ng-directive')).toEqual(true);
|
||||
expect(log).toEqual("found:init");
|
||||
}));
|
||||
|
||||
|
||||
it('should recurse to children', function() {
|
||||
scope = compile('<div><span hello="misko"/></div>');
|
||||
it('should recurse to children', inject(function($rootScope, $compile) {
|
||||
$compile('<div><span hello="misko"/></div>')($rootScope);
|
||||
expect(log).toEqual("hello misko");
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
it('should observe scope', function() {
|
||||
scope = compile('<span observe="name"></span>');
|
||||
it('should observe scope', inject(function($rootScope, $compile) {
|
||||
$compile('<span observe="name"></span>')($rootScope);
|
||||
expect(log).toEqual("");
|
||||
scope.$digest();
|
||||
scope.name = 'misko';
|
||||
scope.$digest();
|
||||
scope.$digest();
|
||||
scope.name = 'adam';
|
||||
scope.$digest();
|
||||
scope.$digest();
|
||||
$rootScope.$digest();
|
||||
$rootScope.name = 'misko';
|
||||
$rootScope.$digest();
|
||||
$rootScope.$digest();
|
||||
$rootScope.name = 'adam';
|
||||
$rootScope.$digest();
|
||||
$rootScope.$digest();
|
||||
expect(log).toEqual(":misko:adam");
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
it('should prevent descend', function() {
|
||||
it('should prevent descend', inject(function($rootScope, $compile) {
|
||||
directives.stop = function() { this.descend(false); };
|
||||
scope = compile('<span hello="misko" stop="true"><span hello="adam"/></span>');
|
||||
$compile('<span hello="misko" stop="true"><span hello="adam"/></span>')($rootScope);
|
||||
expect(log).toEqual("hello misko");
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
it('should allow creation of templates', inject(function($rootScope) {
|
||||
it('should allow creation of templates', inject(function($rootScope, $compile) {
|
||||
directives.duplicate = function(expr, element){
|
||||
element.replaceWith(document.createComment("marker"));
|
||||
element.removeAttr("duplicate");
|
||||
|
|
@ -103,32 +101,32 @@ describe('compiler', function() {
|
|||
});
|
||||
};
|
||||
};
|
||||
scope = compile('before<span duplicate="expr">x</span>after');
|
||||
expect(sortedHtml(scope.$element)).
|
||||
$compile('<div>before<span duplicate="expr">x</span>after</div>')($rootScope);
|
||||
expect(sortedHtml($rootScope.$element)).
|
||||
toEqual('<div>' +
|
||||
'before<#comment></#comment>' +
|
||||
'after' +
|
||||
'</div>');
|
||||
scope.value = 1;
|
||||
scope.$digest();
|
||||
expect(sortedHtml(scope.$element)).
|
||||
$rootScope.value = 1;
|
||||
$rootScope.$digest();
|
||||
expect(sortedHtml($rootScope.$element)).
|
||||
toEqual('<div>' +
|
||||
'before<#comment></#comment>' +
|
||||
'<span>x</span>' +
|
||||
'after' +
|
||||
'</div>');
|
||||
scope.value = 2;
|
||||
scope.$digest();
|
||||
expect(sortedHtml(scope.$element)).
|
||||
$rootScope.value = 2;
|
||||
$rootScope.$digest();
|
||||
expect(sortedHtml($rootScope.$element)).
|
||||
toEqual('<div>' +
|
||||
'before<#comment></#comment>' +
|
||||
'<span>x</span>' +
|
||||
'<span>x</span>' +
|
||||
'after' +
|
||||
'</div>');
|
||||
scope.value = 3;
|
||||
scope.$digest();
|
||||
expect(sortedHtml(scope.$element)).
|
||||
$rootScope.value = 3;
|
||||
$rootScope.$digest();
|
||||
expect(sortedHtml($rootScope.$element)).
|
||||
toEqual('<div>' +
|
||||
'before<#comment></#comment>' +
|
||||
'<span>x</span>' +
|
||||
|
|
@ -139,21 +137,22 @@ describe('compiler', function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should process markup before directives', function() {
|
||||
markup.push(function(text, textNode, parentNode) {
|
||||
it('should process markup before directives', inject(function($rootScope, $compile) {
|
||||
textMmarkup.push(function(text, textNode, parentNode) {
|
||||
if (text == 'middle') {
|
||||
expect(textNode.text()).toEqual(text);
|
||||
parentNode.attr('hello', text);
|
||||
textNode[0].nodeValue = 'replaced';
|
||||
}
|
||||
});
|
||||
scope = compile('before<span>middle</span>after');
|
||||
expect(sortedHtml(scope.$element[0], true)).toEqual('<div>before<span class="ng-directive" hello="middle">replaced</span>after</div>');
|
||||
$compile('<div>before<span>middle</span>after</div>')($rootScope);
|
||||
expect(sortedHtml($rootScope.$element[0], true)).
|
||||
toEqual('<div>before<span class="ng-directive" hello="middle">replaced</span>after</div>');
|
||||
expect(log).toEqual("hello middle");
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
it('should replace widgets', function() {
|
||||
it('should replace widgets', inject(function($rootScope, $compile) {
|
||||
widgets['NG:BUTTON'] = function(element) {
|
||||
expect(element.hasClass('ng-widget')).toEqual(true);
|
||||
element.replaceWith('<div>button</div>');
|
||||
|
|
@ -161,13 +160,13 @@ describe('compiler', function() {
|
|||
log += 'init';
|
||||
};
|
||||
};
|
||||
scope = compile('<ng:button>push me</ng:button>');
|
||||
expect(lowercase(scope.$element[0].innerHTML)).toEqual('<div>button</div>');
|
||||
$compile('<div><ng:button>push me</ng:button></div>')($rootScope);
|
||||
expect(lowercase($rootScope.$element[0].innerHTML)).toEqual('<div>button</div>');
|
||||
expect(log).toEqual('init');
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
it('should use the replaced element after calling widget', function() {
|
||||
it('should use the replaced element after calling widget', inject(function($rootScope, $compile) {
|
||||
widgets['H1'] = function(element) {
|
||||
// HTML elements which are augmented by acting as widgets, should not be marked as so
|
||||
expect(element.hasClass('ng-widget')).toEqual(false);
|
||||
|
|
@ -177,17 +176,17 @@ describe('compiler', function() {
|
|||
this.directives(true);
|
||||
return noop;
|
||||
};
|
||||
markup.push(function(text, textNode, parent){
|
||||
textMmarkup.push(function(text, textNode, parent){
|
||||
if (text == '{{1+2}}')
|
||||
parent.text('3');
|
||||
});
|
||||
scope = compile('<div><h1>ignore me</h1></div>');
|
||||
expect(scope.$element.text()).toEqual('3');
|
||||
});
|
||||
$compile('<div><h1>ignore me</h1></div>')($rootScope);
|
||||
expect($rootScope.$element.text()).toEqual('3');
|
||||
}));
|
||||
|
||||
|
||||
it('should allow multiple markups per text element', function() {
|
||||
markup.push(function(text, textNode, parent){
|
||||
it('should allow multiple markups per text element', inject(function($rootScope, $compile) {
|
||||
textMmarkup.push(function(text, textNode, parent){
|
||||
var index = text.indexOf('---');
|
||||
if (index > -1) {
|
||||
textNode.after(text.substring(index + 3));
|
||||
|
|
@ -196,7 +195,7 @@ describe('compiler', function() {
|
|||
textNode.remove();
|
||||
}
|
||||
});
|
||||
markup.push(function(text, textNode, parent){
|
||||
textMmarkup.push(function(text, textNode, parent){
|
||||
var index = text.indexOf('===');
|
||||
if (index > -1) {
|
||||
textNode.after(text.substring(index + 3));
|
||||
|
|
@ -205,14 +204,13 @@ describe('compiler', function() {
|
|||
textNode.remove();
|
||||
}
|
||||
});
|
||||
scope = compile('A---B---C===D');
|
||||
expect(sortedHtml(scope.$element)).toEqual('<div>A<hr></hr>B<hr></hr>C<p></p>D</div>');
|
||||
});
|
||||
$compile('<div>A---B---C===D</div>')($rootScope);
|
||||
expect(sortedHtml($rootScope.$element)).toEqual('<div>A<hr></hr>B<hr></hr>C<p></p>D</div>');
|
||||
}));
|
||||
|
||||
|
||||
it('should add class for namespace elements', function() {
|
||||
scope = compile('<ng:space>abc</ng:space>');
|
||||
var space = jqLite(scope.$element[0].firstChild);
|
||||
expect(space.hasClass('ng-space')).toEqual(true);
|
||||
});
|
||||
it('should add class for namespace elements', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<ng:space>abc</ng:space>')($rootScope);
|
||||
expect(element.hasClass('ng-space')).toEqual(true);
|
||||
}));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -125,7 +125,6 @@ function inject(){
|
|||
function resetAngularPublic() {
|
||||
extend(angular, {
|
||||
'element': jqLite,
|
||||
'compile': compile,
|
||||
'copy': copy,
|
||||
'extend': extend,
|
||||
'equals': equals,
|
||||
|
|
|
|||
|
|
@ -8,17 +8,17 @@ describe('form', function() {
|
|||
});
|
||||
|
||||
|
||||
it('should attach form to DOM', inject(function($rootScope) {
|
||||
it('should attach form to DOM', inject(function($rootScope, $compile) {
|
||||
doc = angular.element('<form>');
|
||||
angular.compile(doc)($rootScope);
|
||||
$compile(doc)($rootScope);
|
||||
expect(doc.data('$form')).toBeTruthy();
|
||||
}));
|
||||
|
||||
|
||||
it('should prevent form submission', inject(function($rootScope) {
|
||||
it('should prevent form submission', inject(function($rootScope, $compile) {
|
||||
var startingUrl = '' + window.location;
|
||||
doc = angular.element('<form name="myForm"><input type=submit val=submit>');
|
||||
angular.compile(doc)($rootScope);
|
||||
$compile(doc)($rootScope);
|
||||
browserTrigger(doc.find('input'));
|
||||
waitsFor(
|
||||
function() { return true; },
|
||||
|
|
@ -29,18 +29,18 @@ describe('form', function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should publish form to scope', inject(function($rootScope) {
|
||||
it('should publish form to scope', inject(function($rootScope, $compile) {
|
||||
doc = angular.element('<form name="myForm"></form>');
|
||||
angular.compile(doc)($rootScope);
|
||||
$compile(doc)($rootScope);
|
||||
expect($rootScope.myForm).toBeTruthy();
|
||||
expect(doc.data('$form')).toBeTruthy();
|
||||
expect(doc.data('$form')).toEqual($rootScope.myForm);
|
||||
}));
|
||||
|
||||
|
||||
it('should have ng-valide/ng-invalid style', inject(function($rootScope) {
|
||||
it('should have ng-valide/ng-invalid style', inject(function($rootScope, $compile) {
|
||||
doc = angular.element('<form name="myForm"><input type=text ng:model=text required>');
|
||||
angular.compile(doc)($rootScope);
|
||||
$compile(doc)($rootScope);
|
||||
$rootScope.text = 'misko';
|
||||
$rootScope.$digest();
|
||||
|
||||
|
|
@ -54,14 +54,14 @@ describe('form', function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should chain nested forms', inject(function($rootScope) {
|
||||
it('should chain nested forms', inject(function($rootScope, $compile) {
|
||||
doc = angular.element(
|
||||
'<ng:form name=parent>' +
|
||||
'<ng:form name=child>' +
|
||||
'<input type=text ng:model=text name=text>' +
|
||||
'</ng:form>' +
|
||||
'</ng:form>');
|
||||
angular.compile(doc)($rootScope);
|
||||
$compile(doc)($rootScope);
|
||||
var parent = $rootScope.parent;
|
||||
var child = $rootScope.child;
|
||||
var input = child.text;
|
||||
|
|
@ -76,14 +76,14 @@ describe('form', function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should chain nested forms in repeater', inject(function($rootScope) {
|
||||
it('should chain nested forms in repeater', inject(function($rootScope, $compile) {
|
||||
doc = angular.element(
|
||||
'<ng:form name=parent>' +
|
||||
'<ng:form ng:repeat="f in forms" name=child>' +
|
||||
'<input type=text ng:model=text name=text>' +
|
||||
'</ng:form>' +
|
||||
'</ng:form>');
|
||||
angular.compile(doc)($rootScope);
|
||||
$compile(doc)($rootScope);
|
||||
$rootScope.forms = [1];
|
||||
$rootScope.$digest();
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
describe('widget: input', function() {
|
||||
var compile = null, element = null, scope = null, defer = null;
|
||||
var $compile = null;
|
||||
var doc = null;
|
||||
|
||||
beforeEach(inject(function($rootScope) {
|
||||
beforeEach(inject(function($rootScope, $compile) {
|
||||
scope = $rootScope;
|
||||
set$compile($compile);
|
||||
element = null;
|
||||
compile = function(html, parent) {
|
||||
if (parent) {
|
||||
|
|
@ -14,13 +16,15 @@ describe('widget: input', function() {
|
|||
} else {
|
||||
element = jqLite(html);
|
||||
}
|
||||
angular.compile(element)(scope);
|
||||
$compile(element)(scope);
|
||||
scope.$apply();
|
||||
defer = scope.$service('$browser').defer;
|
||||
return scope;
|
||||
};
|
||||
}));
|
||||
|
||||
function set$compile(c) { $compile = c; }
|
||||
|
||||
afterEach(function() {
|
||||
dealoc(element);
|
||||
dealoc(doc);
|
||||
|
|
@ -40,7 +44,7 @@ describe('widget: input', function() {
|
|||
formElement = doc = angular.element('<form name="form"><input ' + prefix +
|
||||
'type="text" ng:model="name" name="name" ng:change="change()"></form>');
|
||||
inputElement = formElement.find('input');
|
||||
angular.compile(doc)(scope);
|
||||
$compile(doc)(scope);
|
||||
form = formElement.inheritedData('$form');
|
||||
};
|
||||
|
||||
|
|
@ -90,16 +94,16 @@ describe('widget: input', function() {
|
|||
});
|
||||
|
||||
|
||||
it('should change non-html5 types to text', inject(function($rootScope) {
|
||||
it('should change non-html5 types to text', inject(function($rootScope, $compile) {
|
||||
doc = angular.element('<form name="form"><input type="abc" ng:model="name"></form>');
|
||||
angular.compile(doc)($rootScope);
|
||||
$compile(doc)($rootScope);
|
||||
expect(doc.find('input').attr('type')).toEqual('text');
|
||||
}));
|
||||
|
||||
|
||||
it('should not change html5 types to text', inject(function($rootScope) {
|
||||
it('should not change html5 types to text', inject(function($rootScope, $compile) {
|
||||
doc = angular.element('<form name="form"><input type="number" ng:model="name"></form>');
|
||||
angular.compile(doc)($rootScope);
|
||||
$compile(doc)($rootScope);
|
||||
expect(doc.find('input')[0].getAttribute('type')).toEqual('number');
|
||||
}));
|
||||
});
|
||||
|
|
@ -454,7 +458,7 @@ describe('widget: input', function() {
|
|||
|
||||
|
||||
describe('scope declaration', function() {
|
||||
it('should read the declaration from scope', inject(function($rootScope) {
|
||||
it('should read the declaration from scope', inject(function($rootScope, $compile) {
|
||||
var input, $formFactory;
|
||||
element = angular.element('<input type="@MyType" ng:model="abc">');
|
||||
$rootScope.MyType = function($f, i) {
|
||||
|
|
@ -463,18 +467,18 @@ describe('widget: input', function() {
|
|||
};
|
||||
$rootScope.MyType.$inject = ['$formFactory'];
|
||||
|
||||
angular.compile(element)($rootScope);
|
||||
$compile(element)($rootScope);
|
||||
|
||||
expect($formFactory).toBe($rootScope.$service('$formFactory'));
|
||||
expect(input[0]).toBe(element[0]);
|
||||
}));
|
||||
|
||||
it('should throw an error of Controller not declared in scope', inject(function($rootScope) {
|
||||
it('should throw an error of Controller not declared in scope', inject(function($rootScope, $compile) {
|
||||
var input, $formFactory;
|
||||
element = angular.element('<input type="@DontExist" ng:model="abc">');
|
||||
var error;
|
||||
try {
|
||||
angular.compile(element)($rootScope);
|
||||
$compile(element)($rootScope);
|
||||
error = 'no error thrown';
|
||||
} catch (e) {
|
||||
error = e;
|
||||
|
|
@ -577,9 +581,9 @@ describe('widget: input', function() {
|
|||
{'ng:maxlength': 3});
|
||||
|
||||
|
||||
it('should throw an error when scope pattern can\'t be found', inject(function($rootScope) {
|
||||
it('should throw an error when scope pattern can\'t be found', inject(function($rootScope, $compile) {
|
||||
var el = jqLite('<input ng:model="foo" ng:pattern="fooRegexp">');
|
||||
angular.compile(el)($rootScope);
|
||||
$compile(el)($rootScope);
|
||||
|
||||
el.val('xx');
|
||||
browserTrigger(el, 'keydown');
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
describe('select', function() {
|
||||
var compile = null, element = null, scope = null;
|
||||
|
||||
beforeEach(inject(function($rootScope) {
|
||||
beforeEach(inject(function($compile, $rootScope) {
|
||||
scope = $rootScope;
|
||||
element = null;
|
||||
compile = function(html, parent) {
|
||||
|
|
@ -13,7 +13,7 @@ describe('select', function() {
|
|||
} else {
|
||||
element = jqLite(html);
|
||||
}
|
||||
angular.compile(element)($rootScope);
|
||||
$compile(element)($rootScope);
|
||||
scope.$apply();
|
||||
return scope;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
'use strict';
|
||||
|
||||
describe("widget", function() {
|
||||
describe('ng:switch', inject(function($rootScope) {
|
||||
it('should switch on value change', inject(function($rootScope) {
|
||||
var element = angular.compile('<ng:switch on="select">' +
|
||||
describe('ng:switch', inject(function($rootScope, $compile) {
|
||||
it('should switch on value change', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
'<ng:switch on="select">' +
|
||||
'<div ng:switch-when="1">first:{{name}}</div>' +
|
||||
'<div ng:switch-when="2">second:{{name}}</div>' +
|
||||
'<div ng:switch-when="true">true:{{name}}</div>' +
|
||||
|
|
@ -27,8 +28,8 @@ describe("widget", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should switch on switch-when-default', inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
it('should switch on switch-when-default', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
'<ng:switch on="select">' +
|
||||
'<div ng:switch-when="1">one</div>' +
|
||||
'<div ng:switch-default>other</div>' +
|
||||
|
|
@ -41,8 +42,8 @@ describe("widget", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should call change on switch', inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
it('should call change on switch', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
'<ng:switch on="url" change="name=\'works\'">' +
|
||||
'<div ng:switch-when="a">{{name}}</div>' +
|
||||
'</ng:switch>')($rootScope);
|
||||
|
|
@ -54,10 +55,10 @@ describe("widget", function() {
|
|||
}));
|
||||
|
||||
|
||||
describe('ng:include', inject(function($rootScope) {
|
||||
it('should include on external file', inject(function($rootScope) {
|
||||
describe('ng:include', inject(function($rootScope, $compile) {
|
||||
it('should include on external file', inject(function($rootScope, $compile) {
|
||||
var element = jqLite('<ng:include src="url" scope="childScope"></ng:include>');
|
||||
var element = angular.compile(element)($rootScope);
|
||||
var element = $compile(element)($rootScope);
|
||||
$rootScope.childScope = $rootScope.$new();
|
||||
$rootScope.childScope.name = 'misko';
|
||||
$rootScope.url = 'myUrl';
|
||||
|
|
@ -67,9 +68,9 @@ describe("widget", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should remove previously included text if a falsy value is bound to src', inject(function($rootScope) {
|
||||
it('should remove previously included text if a falsy value is bound to src', inject(function($rootScope, $compile) {
|
||||
var element = jqLite('<ng:include src="url" scope="childScope"></ng:include>');
|
||||
var element = angular.compile(element)($rootScope);
|
||||
var element = $compile(element)($rootScope);
|
||||
$rootScope.childScope = $rootScope.$new();
|
||||
$rootScope.childScope.name = 'igor';
|
||||
$rootScope.url = 'myUrl';
|
||||
|
|
@ -85,9 +86,9 @@ describe("widget", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should allow this for scope', inject(function($rootScope) {
|
||||
it('should allow this for scope', inject(function($rootScope, $compile) {
|
||||
var element = jqLite('<ng:include src="url" scope="this"></ng:include>');
|
||||
var element = angular.compile(element)($rootScope);
|
||||
var element = $compile(element)($rootScope);
|
||||
$rootScope.url = 'myUrl';
|
||||
$rootScope.$service('$xhr.cache').data.myUrl = {value:'{{"abc"}}'};
|
||||
$rootScope.$digest();
|
||||
|
|
@ -101,9 +102,9 @@ describe("widget", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should evaluate onload expression when a partial is loaded', inject(function($rootScope) {
|
||||
it('should evaluate onload expression when a partial is loaded', inject(function($rootScope, $compile) {
|
||||
var element = jqLite('<ng:include src="url" onload="loaded = true"></ng:include>');
|
||||
var element = angular.compile(element)($rootScope);
|
||||
var element = $compile(element)($rootScope);
|
||||
|
||||
expect($rootScope.loaded).not.toBeDefined();
|
||||
|
||||
|
|
@ -115,9 +116,9 @@ describe("widget", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should destroy old scope', inject(function($rootScope) {
|
||||
it('should destroy old scope', inject(function($rootScope, $compile) {
|
||||
var element = jqLite('<ng:include src="url"></ng:include>');
|
||||
var element = angular.compile(element)($rootScope);
|
||||
var element = $compile(element)($rootScope);
|
||||
|
||||
expect($rootScope.$$childHead).toBeFalsy();
|
||||
|
||||
|
|
@ -133,13 +134,13 @@ describe("widget", function() {
|
|||
}));
|
||||
|
||||
|
||||
describe('a', inject(function($rootScope) {
|
||||
it('should prevent default action to be executed when href is empty', inject(function($rootScope) {
|
||||
describe('a', inject(function($rootScope, $compile) {
|
||||
it('should prevent default action to be executed when href is empty', inject(function($rootScope, $compile) {
|
||||
var orgLocation = document.location.href,
|
||||
preventDefaultCalled = false,
|
||||
event;
|
||||
|
||||
var element = angular.compile('<a href="">empty link</a>')($rootScope);
|
||||
var element = $compile('<a href="">empty link</a>')($rootScope);
|
||||
|
||||
if (msie < 9) {
|
||||
|
||||
|
|
@ -169,9 +170,9 @@ describe("widget", function() {
|
|||
}));
|
||||
|
||||
|
||||
describe('@ng:repeat', inject(function($rootScope) {
|
||||
it('should ng:repeat over array', inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
describe('@ng:repeat', inject(function($rootScope, $compile) {
|
||||
it('should ng:repeat over array', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
'<ul>' +
|
||||
'<li ng:repeat="item in items" ng:init="suffix = \';\'" ng:bind="item + suffix"></li>' +
|
||||
'</ul>')($rootScope);
|
||||
|
|
@ -197,8 +198,8 @@ describe("widget", function() {
|
|||
expect(element.text()).toEqual('brad;');
|
||||
}));
|
||||
|
||||
it('should ng:repeat over object', inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
it('should ng:repeat over object', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
'<ul>' +
|
||||
'<li ng:repeat="(key, value) in items" ng:bind="key + \':\' + value + \';\' "></li>' +
|
||||
'</ul>')($rootScope);
|
||||
|
|
@ -207,12 +208,12 @@ describe("widget", function() {
|
|||
expect(element.text()).toEqual('misko:swe;shyam:set;');
|
||||
}));
|
||||
|
||||
it('should not ng:repeat over parent properties', inject(function($rootScope) {
|
||||
it('should not ng:repeat over parent properties', inject(function($rootScope, $compile) {
|
||||
var Class = function() {};
|
||||
Class.prototype.abc = function() {};
|
||||
Class.prototype.value = 'abc';
|
||||
|
||||
var element = angular.compile(
|
||||
var element = $compile(
|
||||
'<ul>' +
|
||||
'<li ng:repeat="(key, value) in items" ng:bind="key + \':\' + value + \';\' "></li>' +
|
||||
'</ul>')($rootScope);
|
||||
|
|
@ -222,16 +223,16 @@ describe("widget", function() {
|
|||
expect(element.text()).toEqual('name:value;');
|
||||
}));
|
||||
|
||||
it('should error on wrong parsing of ng:repeat', inject(function($rootScope) {
|
||||
it('should error on wrong parsing of ng:repeat', inject(function($rootScope, $compile) {
|
||||
expect(function() {
|
||||
var element = angular.compile('<ul><li ng:repeat="i dont parse"></li></ul>')($rootScope);
|
||||
var element = $compile('<ul><li ng:repeat="i dont parse"></li></ul>')($rootScope);
|
||||
}).toThrow("Expected ng:repeat in form of '_item_ in _collection_' but got 'i dont parse'.");
|
||||
|
||||
$logMock.error.logs.shift();
|
||||
}));
|
||||
|
||||
it('should expose iterator offset as $index when iterating over arrays', inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
it('should expose iterator offset as $index when iterating over arrays', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
'<ul>' +
|
||||
'<li ng:repeat="item in items" ng:bind="item + $index + \'|\'"></li>' +
|
||||
'</ul>')($rootScope);
|
||||
|
|
@ -240,8 +241,8 @@ describe("widget", function() {
|
|||
expect(element.text()).toEqual('misko0|shyam1|frodo2|');
|
||||
}));
|
||||
|
||||
it('should expose iterator offset as $index when iterating over objects', inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
it('should expose iterator offset as $index when iterating over objects', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
'<ul>' +
|
||||
'<li ng:repeat="(key, val) in items" ng:bind="key + \':\' + val + $index + \'|\'"></li>' +
|
||||
'</ul>')($rootScope);
|
||||
|
|
@ -250,9 +251,8 @@ describe("widget", function() {
|
|||
expect(element.text()).toEqual('frodo:f0|misko:m1|shyam:s2|');
|
||||
}));
|
||||
|
||||
it('should expose iterator position as $position when iterating over arrays',
|
||||
inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
it('should expose iterator position as $position when iterating over arrays', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
'<ul>' +
|
||||
'<li ng:repeat="item in items" ng:bind="item + \':\' + $position + \'|\'"></li>' +
|
||||
'</ul>')($rootScope);
|
||||
|
|
@ -270,8 +270,8 @@ describe("widget", function() {
|
|||
expect(element.text()).toEqual('misko:first|shyam:last|');
|
||||
}));
|
||||
|
||||
it('should expose iterator position as $position when iterating over objects', inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
it('should expose iterator position as $position when iterating over objects', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
'<ul>' +
|
||||
'<li ng:repeat="(key, val) in items" ng:bind="key + \':\' + val + \':\' + $position + \'|\'">' +
|
||||
'</li>' +
|
||||
|
|
@ -286,8 +286,8 @@ describe("widget", function() {
|
|||
expect(element.text()).toEqual('misko:m:first|shyam:s:last|');
|
||||
}));
|
||||
|
||||
it('should ignore $ and $$ properties', inject(function($rootScope) {
|
||||
var element = angular.compile('<ul><li ng:repeat="i in items">{{i}}|</li></ul>')($rootScope);
|
||||
it('should ignore $ and $$ properties', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<ul><li ng:repeat="i in items">{{i}}|</li></ul>')($rootScope);
|
||||
$rootScope.items = ['a', 'b', 'c'];
|
||||
$rootScope.items.$$hashkey = 'xxx';
|
||||
$rootScope.items.$root = 'yyy';
|
||||
|
|
@ -296,8 +296,8 @@ describe("widget", function() {
|
|||
expect(element.text()).toEqual('a|b|c|');
|
||||
}));
|
||||
|
||||
it('should repeat over nested arrays', inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
it('should repeat over nested arrays', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
'<ul>' +
|
||||
'<li ng:repeat="subgroup in groups">' +
|
||||
'<div ng:repeat="group in subgroup">{{group}}|</div>X' +
|
||||
|
|
@ -309,8 +309,8 @@ describe("widget", function() {
|
|||
expect(element.text()).toEqual('a|b|Xc|d|X');
|
||||
}));
|
||||
|
||||
it('should ignore non-array element properties when iterating over an array', inject(function($rootScope) {
|
||||
var element = angular.compile('<ul><li ng:repeat="item in array">{{item}}|</li></ul>')($rootScope);
|
||||
it('should ignore non-array element properties when iterating over an array', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<ul><li ng:repeat="item in array">{{item}}|</li></ul>')($rootScope);
|
||||
$rootScope.array = ['a', 'b', 'c'];
|
||||
$rootScope.array.foo = '23';
|
||||
$rootScope.array.bar = function() {};
|
||||
|
|
@ -319,8 +319,8 @@ describe("widget", function() {
|
|||
expect(element.text()).toBe('a|b|c|');
|
||||
}));
|
||||
|
||||
it('should iterate over non-existent elements of a sparse array', inject(function($rootScope) {
|
||||
var element = angular.compile('<ul><li ng:repeat="item in array">{{item}}|</li></ul>')($rootScope);
|
||||
it('should iterate over non-existent elements of a sparse array', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<ul><li ng:repeat="item in array">{{item}}|</li></ul>')($rootScope);
|
||||
$rootScope.array = ['a', 'b'];
|
||||
$rootScope.array[4] = 'c';
|
||||
$rootScope.array[6] = 'd';
|
||||
|
|
@ -333,8 +333,8 @@ describe("widget", function() {
|
|||
describe('stability', function() {
|
||||
var a, b, c, d, lis, element;
|
||||
|
||||
beforeEach(inject(function($rootScope) {
|
||||
element = angular.compile(
|
||||
beforeEach(inject(function($rootScope, $compile) {
|
||||
element = $compile(
|
||||
'<ul>' +
|
||||
'<li ng:repeat="item in items" ng:bind="key + \':\' + val + \':\' + $position + \'|\'"></li>' +
|
||||
'</ul>')($rootScope);
|
||||
|
|
@ -348,7 +348,7 @@ describe("widget", function() {
|
|||
lis = element.find('li');
|
||||
}));
|
||||
|
||||
it('should preserve the order of elements', inject(function($rootScope) {
|
||||
it('should preserve the order of elements', inject(function($rootScope, $compile) {
|
||||
$rootScope.items = [a, c, d];
|
||||
$rootScope.$digest();
|
||||
var newElements = element.find('li');
|
||||
|
|
@ -357,7 +357,7 @@ describe("widget", function() {
|
|||
expect(newElements[2]).not.toEqual(lis[1]);
|
||||
}));
|
||||
|
||||
it('should support duplicates', inject(function($rootScope) {
|
||||
it('should support duplicates', inject(function($rootScope, $compile) {
|
||||
$rootScope.items = [a, a, b, c];
|
||||
$rootScope.$digest();
|
||||
var newElements = element.find('li');
|
||||
|
|
@ -382,7 +382,7 @@ describe("widget", function() {
|
|||
expect(newElements[3]).toEqual(lis[3]);
|
||||
}));
|
||||
|
||||
it('should remove last item when one duplicate instance is removed', inject(function($rootScope) {
|
||||
it('should remove last item when one duplicate instance is removed', inject(function($rootScope, $compile) {
|
||||
$rootScope.items = [a, a, a];
|
||||
$rootScope.$digest();
|
||||
lis = element.find('li');
|
||||
|
|
@ -395,7 +395,7 @@ describe("widget", function() {
|
|||
expect(newElements[1]).toEqual(lis[1]);
|
||||
}));
|
||||
|
||||
it('should reverse items when the collection is reversed', inject(function($rootScope) {
|
||||
it('should reverse items when the collection is reversed', inject(function($rootScope, $compile) {
|
||||
$rootScope.items = [a, b, c];
|
||||
$rootScope.$digest();
|
||||
lis = element.find('li');
|
||||
|
|
@ -413,8 +413,8 @@ describe("widget", function() {
|
|||
|
||||
|
||||
describe('@ng:non-bindable', function() {
|
||||
it('should prevent compilation of the owning element and its children', inject(function($rootScope) {
|
||||
var element = angular.compile('<div ng:non-bindable><span ng:bind="name"></span></div>')($rootScope);
|
||||
it('should prevent compilation of the owning element and its children', inject(function($rootScope, $compile) {
|
||||
var element = $compile('<div ng:non-bindable><span ng:bind="name"></span></div>')($rootScope);
|
||||
$rootScope.name = 'misko';
|
||||
$rootScope.$digest();
|
||||
expect(element.text()).toEqual('');
|
||||
|
|
@ -424,19 +424,19 @@ describe("widget", function() {
|
|||
|
||||
describe('ng:view', function() {
|
||||
var element;
|
||||
beforeEach(inject(function($rootScope) {
|
||||
element = angular.compile('<ng:view></ng:view>')($rootScope);
|
||||
beforeEach(inject(function($rootScope, $compile) {
|
||||
element = $compile('<ng:view></ng:view>')($rootScope);
|
||||
}));
|
||||
|
||||
|
||||
it('should do nothing when no routes are defined', inject(function($rootScope, $location) {
|
||||
it('should do nothing when no routes are defined', inject(function($rootScope, $compile, $location) {
|
||||
$location.path('/unknown');
|
||||
$rootScope.$digest();
|
||||
expect(element.text()).toEqual('');
|
||||
}));
|
||||
|
||||
|
||||
it('should load content via xhr when route changes', inject(function($rootScope, $browser, $location, $route) {
|
||||
it('should load content via xhr when route changes', inject(function($rootScope, $compile, $browser, $location, $route) {
|
||||
$route.when('/foo', {template: 'myUrl1'});
|
||||
$route.when('/bar', {template: 'myUrl2'});
|
||||
|
||||
|
|
@ -456,7 +456,7 @@ describe("widget", function() {
|
|||
}));
|
||||
|
||||
it('should remove all content when location changes to an unknown route',
|
||||
inject(function($rootScope, $location, $browser, $route) {
|
||||
inject(function($rootScope, $compile, $location, $browser, $route) {
|
||||
$route.when('/foo', {template: 'myUrl1'});
|
||||
|
||||
$location.path('/foo');
|
||||
|
|
@ -471,7 +471,7 @@ describe("widget", function() {
|
|||
}));
|
||||
|
||||
it('should chain scopes and propagate evals to the child scope',
|
||||
inject(function($rootScope, $location, $browser, $route) {
|
||||
inject(function($rootScope, $compile, $location, $browser, $route) {
|
||||
$route.when('/foo', {template: 'myUrl1'});
|
||||
$rootScope.parentVar = 'parent';
|
||||
|
||||
|
|
@ -496,7 +496,7 @@ describe("widget", function() {
|
|||
var $route = injector('$route');
|
||||
$route.when('/foo', {controller: angular.noop, template: 'viewPartial.html'});
|
||||
|
||||
var element = angular.compile(
|
||||
var element = injector('$compile')(
|
||||
'<div>' +
|
||||
'include: <ng:include src="\'includePartial.html\'"> </ng:include>' +
|
||||
'</div>')(myApp);
|
||||
|
|
@ -512,8 +512,8 @@ describe("widget", function() {
|
|||
}));
|
||||
|
||||
it('should initialize view template after the view controller was initialized even when ' +
|
||||
'templates were cached', inject(function($rootScope, $location, $browser, $route) {
|
||||
// this is a test for a regression that was introduced by making the ng:view cache sync
|
||||
'templates were cached', inject(function($rootScope, $compile, $location, $browser, $route) {
|
||||
//this is a test for a regression that was introduced by making the ng:view cache sync
|
||||
|
||||
$route.when('/foo', {controller: ParentCtrl, template: 'viewPartial.html'});
|
||||
|
||||
|
|
@ -576,8 +576,8 @@ describe("widget", function() {
|
|||
|
||||
describe('deal with pluralized strings without offset', function() {
|
||||
var element;
|
||||
beforeEach(inject(function($rootScope) {
|
||||
element = angular.compile(
|
||||
beforeEach(inject(function($rootScope, $compile) {
|
||||
element = $compile(
|
||||
'<ng:pluralize count="email"' +
|
||||
"when=\"{'0': 'You have no new email'," +
|
||||
"'one': 'You have one new email'," +
|
||||
|
|
@ -585,7 +585,7 @@ describe("widget", function() {
|
|||
'</ng:pluralize>')($rootScope);
|
||||
}));
|
||||
|
||||
it('should show single/plural strings', inject(function($rootScope) {
|
||||
it('should show single/plural strings', inject(function($rootScope, $compile) {
|
||||
$rootScope.email = 0;
|
||||
$rootScope.$digest();
|
||||
expect(element.text()).toBe('You have no new email');
|
||||
|
|
@ -624,7 +624,7 @@ describe("widget", function() {
|
|||
}));
|
||||
|
||||
|
||||
it('should show single/plural strings with mal-formed inputs', inject(function($rootScope) {
|
||||
it('should show single/plural strings with mal-formed inputs', inject(function($rootScope, $compile) {
|
||||
$rootScope.email = '';
|
||||
$rootScope.$digest();
|
||||
expect(element.text()).toBe('');
|
||||
|
|
@ -665,8 +665,8 @@ describe("widget", function() {
|
|||
|
||||
|
||||
describe('deal with pluralized strings with offset', function() {
|
||||
it('should show single/plural strings with offset', inject(function($rootScope) {
|
||||
var element = angular.compile(
|
||||
it('should show single/plural strings with offset', inject(function($rootScope, $compile) {
|
||||
var element = $compile(
|
||||
"<ng:pluralize count=\"viewCount\" offset=2 " +
|
||||
"when=\"{'0': 'Nobody is viewing.'," +
|
||||
"'1': '{{p1}} is viewing.'," +
|
||||
|
|
|
|||
Loading…
Reference in a new issue