Is there any way I can use functions of these libraries in my angular factory?
<head>
<script type="text/javascript" src="js/3rdparty/strophe.js"></script>
<script type="text/javascript" src="js/3rdparty/xml2json.js"></script>
<script src="js/app.js"></script>
<script src="js/services.js"></script>
<script src="js/controller.js"></script>
</head>
I have a factory and a controller. I want to use the libraries (strophe.js, xml2json.js) with my angular code.
This is how I a using it but it is always giving me an error
angular.module('fairy_chat.services',['globals'])
// ----------- chat factory : ------------------
.factory('chat_factory', function (CONSTANT, strophe){
var chat_service_obj = {
var connection = new Strophe.Connection(CONSTANT.BOSH_SERVICE);
console.log(connection);
connect_server:function (){
console.log('constant=='+ CONSTANT.BOSH_SERVICE );
}
}
return chat_service_obj;
});
My controller.js
angular.module('fairy_chat.controllers',['fairy_chat.services','ionic','globals'])
.controller('LoginCtrl', function($scope, $state, chat_factory) {
$scope.data = {
username:"",
password:""
};
$scope.login = function(strophe){
chat_factory.connect_server();
}
})
You've got a var within a var
This doesn't look right:
var chat_service_obj = {
var connection = new Strophe.Connection
Should be more like
var chat_service_obj = {
connection: new Strophe.Connection
Try this for your 'chat factory' definition:
// ----------- chat factory : ------------------
.factory('chat_factory', function(CONSTANT, strophe) {
var connection = new Strophe.Connection(CONSTANT.BOSH_SERVICE);
console.log(connection);
var chat_service_obj = {
connect_server: function() {
console.log('constant==' + CONSTANT.BOSH_SERVICE);
}
}
return chat
_service_obj;
});