According to the docs, the function returned by $compile()
takes a Scope object as its first argument. You supply a normal JS object (which does not have an $apply
method of course).
If you want to create a new scope, you can inject the $rootScope
(through Dependency Injection) and use its $new()
method:
app.factory('myFactory', function($rootScope) {
var scope = $rootScope.$new();
...
});
It seems a little bizarre to create an new scope inside a factory though, so providing more details on what you are ultimately trying to achieve might help someone suggest a better approach.