mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-08 23:04:45 +00:00
revert: fix($compile): correct controller instantiation...
fix($compile): correct controller for async directives This reverts commit51d32243feas well as commit9c51d50318Changing ordering of events in stable branch is not a good idea.
This commit is contained in:
parent
0d7f19bb62
commit
166e0d63d0
2 changed files with 3 additions and 123 deletions
|
|
@ -1008,10 +1008,9 @@ function $CompileProvider($provide) {
|
||||||
replaceWith(linkRootElement, jqLite(beforeTemplateLinkNode), linkNode);
|
replaceWith(linkRootElement, jqLite(beforeTemplateLinkNode), linkNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
afterTemplateNodeLinkFn(
|
afterTemplateNodeLinkFn(function() {
|
||||||
beforeTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, linkNode, $rootElement, controller),
|
beforeTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, linkNode, $rootElement, controller);
|
||||||
scope, linkNode, $rootElement, controller
|
}, scope, linkNode, $rootElement, controller);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
linkQueue = null;
|
linkQueue = null;
|
||||||
}).
|
}).
|
||||||
|
|
|
||||||
|
|
@ -2216,125 +2216,6 @@ describe('$compile', function() {
|
||||||
expect(asyncCtrlSpy).toHaveBeenCalledOnce();
|
expect(asyncCtrlSpy).toHaveBeenCalledOnce();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should instantiate the controller after the isolate scope bindings are initialized (with template)', function () {
|
|
||||||
module(function () {
|
|
||||||
var Ctrl = function ($scope, log) {
|
|
||||||
log('myFoo=' + $scope.myFoo);
|
|
||||||
};
|
|
||||||
|
|
||||||
directive('myDirective', function () {
|
|
||||||
return {
|
|
||||||
scope: {
|
|
||||||
myFoo: "="
|
|
||||||
},
|
|
||||||
template: '<p>Hello</p>',
|
|
||||||
controller: Ctrl
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
inject(function ($templateCache, $compile, $rootScope, log) {
|
|
||||||
$rootScope.foo = "bar";
|
|
||||||
|
|
||||||
element = $compile('<div my-directive my-foo="foo"></div>')($rootScope);
|
|
||||||
$rootScope.$apply();
|
|
||||||
expect(log).toEqual('myFoo=bar');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
it('should instantiate the controller after the isolate scope bindings are initialized (with templateUrl)', function () {
|
|
||||||
module(function () {
|
|
||||||
var Ctrl = function ($scope, log) {
|
|
||||||
log('myFoo=' + $scope.myFoo);
|
|
||||||
};
|
|
||||||
|
|
||||||
directive('myDirective', function () {
|
|
||||||
return {
|
|
||||||
scope: {
|
|
||||||
myFoo: "="
|
|
||||||
},
|
|
||||||
templateUrl: 'hello.html',
|
|
||||||
controller: Ctrl
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
inject(function ($templateCache, $compile, $rootScope, log) {
|
|
||||||
$templateCache.put('hello.html', '<p>Hello</p>');
|
|
||||||
$rootScope.foo = "bar";
|
|
||||||
|
|
||||||
element = $compile('<div my-directive my-foo="foo"></div>')($rootScope);
|
|
||||||
$rootScope.$apply();
|
|
||||||
expect(log).toEqual('myFoo=bar');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
it('should allow controller usage in pre-link directive functions with templateUrl', function () {
|
|
||||||
module(function () {
|
|
||||||
var Ctrl = function (log) {
|
|
||||||
log('instance');
|
|
||||||
};
|
|
||||||
|
|
||||||
directive('myDirective', function () {
|
|
||||||
return {
|
|
||||||
scope: true,
|
|
||||||
templateUrl: 'hello.html',
|
|
||||||
controller: Ctrl,
|
|
||||||
compile: function () {
|
|
||||||
return {
|
|
||||||
pre: function (scope, template, attr, ctrl) {},
|
|
||||||
post: function () {}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
inject(function ($templateCache, $compile, $rootScope, log) {
|
|
||||||
$templateCache.put('hello.html', '<p>Hello</p>');
|
|
||||||
|
|
||||||
element = $compile('<div my-directive></div>')($rootScope);
|
|
||||||
$rootScope.$apply();
|
|
||||||
|
|
||||||
expect(log).toEqual('instance');
|
|
||||||
expect(element.text()).toBe('Hello');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
it('should allow controller usage in pre-link directive functions with a template', function () {
|
|
||||||
module(function () {
|
|
||||||
var Ctrl = function (log) {
|
|
||||||
log('instance');
|
|
||||||
};
|
|
||||||
|
|
||||||
directive('myDirective', function () {
|
|
||||||
return {
|
|
||||||
scope: true,
|
|
||||||
template: '<p>Hello</p>',
|
|
||||||
controller: Ctrl,
|
|
||||||
compile: function () {
|
|
||||||
return {
|
|
||||||
pre: function (scope, template, attr, ctrl) {},
|
|
||||||
post: function () {}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
inject(function ($templateCache, $compile, $rootScope, log) {
|
|
||||||
element = $compile('<div my-directive></div>')($rootScope);
|
|
||||||
$rootScope.$apply();
|
|
||||||
|
|
||||||
expect(log).toEqual('instance');
|
|
||||||
expect(element.text()).toBe('Hello');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue