我已经在控制器内部创建了一个名为Call的工厂我在$ scope中有一个Calls数组。我想要做的是更新Call对象并更新$ scope。我已经尝试过使用$,但是我无法完成它的工作,即使可以,它也有点过分了......
当工厂对象被修改时,如何更新$ scope ?
var ctiApp = angular.module('ctiApp', []);
ctiApp.controller('PhoneController', function($scope,$interval,$http,Call,$rootScope){
$scope.calls = [
];
$scope.dial = function(number){
var call = new Call();
call.dial(number);
$scope.calls.push(call);
}
});
// Factory
ctiApp.factory('Call',['$rootScope','$http', function($rootScope ,$http){
var Call = function() {
this.channel='';
this.uid='';
this.time='00:00:00';
this.state='connecting';
this.callerid='';
}
Call.prototype.dial = function(number){
$http({method: 'GET', url: '/url'}).
success(function(data, status, headers, config) {
if(data.data.response==='Success'){
console.log('#CONNECTED');
this.state = 'connected';
this.time = '00:00:00';
this.uid = data.data.uniqueid;
this.channel = data.data.channel;
this.callerid = number;
}
});
}
return Call;
}]);
注:我已经拆出来的大部分功能了这些功能,这就是为什么有一些$ HTTP,$间隔等,仍落后....
这就是我最初使用,但返回一个类而不是更容易。使用新关键字时未遇到问题。 – Mattisdada