Reputation: 83
So I'm reading the AngularFire documentation on 3-way-binding and am trying to do it without $scope. This is my controller:
angular.module('APP', ['firebase']).controller('Ctrl', Ctrl);
Ctrl.$inject = ['$firebaseObject'];
function Ctrl($firebaseObject) {
var vm = this;
var ref = new Firebase('https://testfirebase23.firebaseio.com/');
var syncObj = $firebaseObject(ref);
syncObj.$bindTo(vm, 'data');
}
When I run the code I get this error:
TypeError: undefined is not a function
at e (angularfire.min.js:12)
at Object.e.bindTo (angularfire.min.js:12)
at angularfire.min.js:12
at processQueue (angular.js:13248)
at angular.js:13264
at Scope.$eval (angular.js:14466)
at Scope.$digest (angular.js:14282)
at Scope.$apply (angular.js:14571)
at angular.js:16308
at completeOutstandingRequest (angular.js:4924)
I don't understand the error. Is there a way to 3-way-bind an object or array to tbe controller without $scope?
Upvotes: 1
Views: 627
Reputation: 1119
I recently started studying about the AngularFire as I'm new to this, while doing R&D I got through this: $bindTo() had a strong dependency on the $scope. For the reference you can see this Firebase 3-way data binding with ControllerAs syntax.
Upvotes: 0
Reputation: 136154
$bindTo
of firebase will never work with controllerAs
syntax,
You could achieve this by assign you firebase
object directly to any controller context variable.
Code
var ref = new Firebase('https://testfirebase23.firebaseio.com/');
vm.syncObj = $firebaseObject(ref); //this will ensure your binding will work
Refer this SO answer to
Upvotes: 1