I am trying to create a chat application with angular on the front end.
I added a new function called isUserTyping to the controler of the chat and tested in on chrome. it worked fine.
in explorer however the page does not load with that function (once I remove it it works fine). Ther error I get in the consoelo is this:
"SCRIPT5022: [$injector:modulerr] Failed to instantiate module mymodule due to: Error: [$injector:nomod] Module 'mymodule' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument."
I don't know what this error means.... I attached below the code I have.
If someone has any idea to what causes this in explorer I will greatly appraicate it.
script js:
var mymodule = angular.module('mymodule', ['ngRoute']);
mymodule.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl : 'pages/enter.html',
controller : 'SharedController'
})
.when('/chat', {
templateUrl : 'pages/chat.html',
controller : 'cntrlChat'
});
});
mymodule.factory('myService', function() {
var savedData = {}
var set=function (data) {
savedData = data;
}
function get() {
return savedData;
}
return {
set: set,
get: get
}
});
mymodule.controller('SharedController', ['$scope', 'myService','$location',
function($scope, myService, $location){
$scope.updateMsg = function (msg) {
myService.set(msg);
$location.path("chat");
}
$scope.getMsg = function () {
$scope.message = myService.get();
}
}]);
mymodule.controller("cntrlChat", ['$scope', 'myService','$q','$timeout',
function($scope, myService,$q,$timeout){
var socket = io();
$scope.messages = [];
$scope.room= myService.get();
socket.emit('room', $scope.room);
$scope.submit=function(){
socket.emit('chat_message',{ room: $scope.room, msg: $scope.room+": "+$scope.insertedText });
$scope.insertedText='';
return false;
}
socket.on('chat_message', function(msg){
$scope.$apply(function() {
$scope.messages.push(msg);
});
});
socket.on('info_message', function(msg){
$scope.$apply(function() {
$scope.info=msg;
});
});
$scope.isUserTyping= function() {
var runTwoFunctionWithSleepBetweenThem=function(foo1, foo2, time) {
$q.when(foo1()).then(() => $timeout(foo2, time));
}
runTwoFunctionWithSleepBetweenThem(function (){socket.emit('info_message', { room: $scope.room, msg: 'user is typing...' })},
function (){socket.emit('info_message', { room: $scope.room, msg: '' });},1500);
}
}]);
html
*<form ng-submit="submit()">
{{info}}
<br>
<input autocomplete="off" ng-model="insertedText" ng-change="isUserTyping()" type="text" />
<button type="button" ng-click="submit()">
Send
</button>
</form>*