Code Ethics | 16 Jun 18:07 2015
Picon

angular forms validation issues when using plugins

I have an Single Page Application build using Angular and i am having some issues with the form.

Form is using a check box a drop down and two text boxes.

first text box (Name) has no validation.

check-Box is using a third party plugin called "iCheck".

Drop down is using a plugin called "bootstrap-select".

Validation is using a library called "Jquery Validation Engine".

The plunker is setup here



The expected behavior is. In simple words the text box and drop down are required if check-box is checked.

1) On Page load because form is not dirty (none of the controls were supplied any value) if i click the save button it should hit the save function because there were no validation on the controls, hence there should be no validation message prompt on the screen.

2) If i click the check box. the drop down and the text box below becomes required. it means that both drop down and text box has conditional validation (feature of Jquery Validation Engine) which is already setup and working . so now if i click Save, it should not hit the save function and display the validation prompt.

3) it should keep on restricting the function access and display the validation error prompt unless form controls are valid i.e. some value is selected in drop-down and text boxed is filled.

4) and if i un-check, validation described in point number 3 goes away.

But whats happening is:

a) On page load if i click the save button it does not hit the save function.

b) If i click the check box it still does not hit the save function and validation error prompts are display on both drop down and text-box which is fine thats how it should behave.

c) When is fill the required text box it makes the form ng-valid and it hit the save function how ever the drop is still in ng-invalid.

d) Even if i select some thing from the drop down the validation prompt remains on the drop down and it still hits the save functions.

e) (Not that much worried about this issue) lastly want to setup a custom value in the drop down that should act as default e.g. "--Select One--" and if the default is selected it should be considered as nothing is selected and it should be considered as invalid when validation is active.

all of this code is in dashboard.html and dashboard.js since i am using plugins so i needed directives to work with them properly. Directives for check-box, Select and Validation are in dashboard.js under the controller code.


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscribe <at> googlegroups.com.
To post to this group, send email to angular <at> googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Amitava Ghosh | 16 Jun 15:46 2015
Picon

angular dirty checking

should I put https://gist.github.com/argentum47/3719d7ce6b6156fa1a46#file-profilescontroller-js-L37-l73 these outside the index action, globally inside the controller?
it won't re-render the vm.profile everytime I hit the index action ? bcoz of the angular's digest cycle ?

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscribe <at> googlegroups.com.
To post to this group, send email to angular <at> googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Kushal Kumar | 16 Jun 11:02 2015
Picon

Problem while performing POST request from angular JS login page to authenticate.php on tomcat server

I have created a login form in angular jS with the below mentioned code.

 <form id=loginform class=form-horizontal role=form name=myform ng-submit=login1() novalidate method="post">
                   <div style="margin-bottom: 25px" class=input-group>
                     <span class=input-group-addon><i class="glyphicon glyphicon-user"></i></span> <input name=username type=text class=form-control id=id_username ng-model=user.username ng-required=true>
                     <p class="error validationerror" ng-show="myform.username.$invalid && myform.username.$touched"></p>
                  </div>
                  <div style="margin-bottom: 25px" class=input-group>
                     <span class=input-group-addon><i class="glyphicon glyphicon-lock"></i></span> <input id=login-password type=password class=form-control name=password ng-model=user.password ng-required=true>
                     <p class="error validationerror" ng-show="myform.password.$invalid && myform.password.$touched"></p>
                  </div>
                  <span id="message"></span>

                  <div class=input-group>
                     <div class=checkbox><label><input id=login-remember type=checkbox name=remember value=1> Remember me</label></div>
                  </div>
                  <div style=margin-top:10px class=form-group>
                     <div class="col-sm-12 controls"><button type=submit href=#/login class="btn btn-primary" ng-disabled=myform.$invalid>Login</button></div>
                  </div>
               </form>

Now I implement the login1 function on my custom dashboard.min.js file as shown below.


angular.module("RDash").config(["$stateProvider", "$urlRouterProvider", function(e, t) {
    t.otherwise("/logg"), e.state("verify", {
        url: "/verify",
        templateUrl: "php/verifyAuthentication.php"
    })
}]);

function LoginController(s, l, h) {
    s.login1 = function() {
      console.log(s.user.username);
        var data = $.param({
            json: JSON.stringify({
                name: s.user.username,
                pass: s.user.password
            })
        });
        h.post(l.path("/verify"), data).success(function(data, status) {
            console.log(data);
        })
    }
}

angular.module("RDash").controller("LoginController", ["$scope", "$location", "$http", LoginController]);

I have deployed the entire code in apache tomcat and i am facing a POST error on clicking submit. The error is : 
Note : The submit button posts the request to a verifyAuthentication.php page..(Check above)

POST http://localhost:8080/tailf/[object%20Object] 404 (Not Found)

Can somebody let me know as to why am I facing this issue.


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscribe <at> googlegroups.com.
To post to this group, send email to angular <at> googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Anil Singh | 16 Jun 07:36 2015
Picon

Re: Model binding Radio buttons to a boolean.

It might help you! go to  link http://embed.plnkr.co/XutHOu/preview

Thank you!
http://www.code-sample.com/2014/09/angularjs-documentation.html
----------------------------------------------------------------------------------

On Monday, April 16, 2012 at 8:27:41 AM UTC+5:30, Adam Webber wrote:
Hi,

I am having trouble binding a radio button to a boolean model value.

Is it possible?


Thanks, Adam.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscribe <at> googlegroups.com.
To post to this group, send email to angular <at> googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
van | 16 Jun 07:36 2015
Picon

Serverside pagination using ngtable

Is there anybody to notice my question?
Expecting some suggestions , to move me in right direction!

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscribe <at> googlegroups.com.
To post to this group, send email to angular <at> googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Prosh | 16 Jun 06:52 2015
Picon

Dynamic DOM not trigger button click.

I am using a table structure and apply datatable.net to it. Table populating its row and column data by angularjs and there is also edit or delete button. All are working fine. as soon as i want to implement nested table i just put a hidden td and when we click on expand i dynamically convert td to tr. But dynamically created tr not support any angular event like click etc.
I hope its using bind onclick how we bing "live" onclick of jquery in angularjs.
Please guide us.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscribe <at> googlegroups.com.
To post to this group, send email to angular <at> googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
van | 16 Jun 06:50 2015
Picon

Angular JS serverside Pagination on ngtable

Angular JS serverside Pagination: Pagination controllers are not going to display

I am trying to implement serverside pagination using Angular js. Console is not showing any error.

This is the script:

$scope.get_users = function () { $scope.tableParams = new ngTableParams({ page: 1, count: 5 }, { getData: function ($defer, params) { var start = (params.page() - 1) * params.count(); var end = params.page() * params.count(); $http.get('../admin/users/angular_all_users', { params: { pageNumber: params.page() - 1, rangeStart: start, rangeStop: end } }).success(function (data, status) { var orderedData = params.sorting() ? $filter('orderBy')(data, params.orderBy()) : data; params.total(orderedData.length); $defer.resolve(orderedData.slice(start, end)); }); } }); }

This is my View:

Search: <input type="text" ng-model="query" />Page: {{tableParams.page()}} Count: {{tableParams.count()}} <table ng-table="tableParams" class="table table-striped table-bordered table-hover" id="table_all_users"> <tbody ng-init="get_users()"> <tr class="gradeX" ng-repeat="user in $data | filter:query"> <td width="20%" data-title="'Select'"> <input type="checkbox" name="list[]" class="chk_all" value="" id="" onclick="uncheck_select_all(this);" /> </td> <td width="35%" data-title="'User Name'" sortable="'username'">{{ user.username }}</td> <td width="25%" data-title="'First Name'" sortable="'fname'">{{ user.fname }}</td> <td width="25%" data-title="'Last Name'" sortable="'lname'">{{ user.lname }}</td> <td width="15%" data-title="'Mobile'" sortable="'mobile'">{{ user.mobile }}</td> <td width="15%" data-title="'Email'" sortable="'email'">{{ user.email }}</td> <td width="15%" data-title="'Action'"><a title="Edit User" href="#/edit_user/{{user.user_id}}"><span class="fa fa-pencil"></span></a> | <a title="Delete User" id="" style="cursor:pointer;" ng-click="delete_user(user.user_id)"><span class="fa fa-trash-o"></span></a> </td> </tr> </tbody> </table>

Controller Functions:

public function users_count() { $id = 1; $users_count = $this - > vanesh_model - > get_users_count($id); print json_encode($users_count); } public function angular_all_users() { $pageNumber = $_GET['pageNumber']; if (isset($_GET['rangeStop'])) { $limit = $_GET['rangeStop']; } else { $limit = 10; } $pageNumber = 1; $offset = ($pageNumber * $limit) - $limit; $id = 1; $data['all_users'] = $this - > vanesh_model - > get_all_users($id, $limit, $offset); print json_encode($data['all_users']); }

Where is the problem? I doubt on my controller function : angular_all_users() Please suggest any solution.


Question on Stackoverflow: http://stackoverflow.com/questions/30847735/angular-js-serverside-pagination-pagination-controllers-are-not-going-to-displa

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscribe <at> googlegroups.com.
To post to this group, send email to angular <at> googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Robert Gurule | 15 Jun 16:58 2015
Picon

angular and IE 8 support

Does anybody know if there are issues with angular and IE 8, and if so will 
the next version of angular fix this?

Cheers,

Robert

Miqdad Ali | 15 Jun 16:18 2015
Picon

Angular SEO and Social Networking Crawler

Hey Guys,

I have created AngularJS application, were users can post the content. Now I need to know how to implement SEO and social network crawler for user created content

http://weekendtrails.com/

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscribe <at> googlegroups.com.
To post to this group, send email to angular <at> googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
akuk | 15 Jun 14:18 2015
Picon

Redirect to home page after successful authentication message received from Perl Rest API (Dancer2)

Hi

I am creating a webapp authentication using perl at backend and AngularJS at frontend. http.get is returning a valid result from the backend but I am not sure how to redirect to home.html after succesfull authentication received from the API

#### Index,html

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>TarView Login</title>

    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" href="css/bootstrap.min.css">

    <link rel="stylesheet" href="css/prod/styles.css">

    <script src="ajs/lib/angular.min.js"></script>

</head>



<body ng-app="TarView">



<div ng-controller="LoginController" >

    <form ng-submit="loginForm.submit()">

        <input type="text" name="username" value="" placeholder="Username" ng-model="loginForm.username" required><br/>

        <input type="password" name="password"  value="" placeholder = "Password" ng-model="loginForm.password" required><br/>



            <!-- button type="submit" id="login" class="btn btn-primary">Login</button-->

<button type="submit" id="submit" class="btn btn-primary">Login</button>

            <!-- a href="#/register" class="btn btn-link">Register</a> -->

</form>


  <script src="ajs/app/app.js"></script>

</div>

</body>

</html>

### app.js #####

var app = angular.module("TarView", []);

app.controller("LoginController", ['$scope', '$http', function($scope) {

                $scope.authData = []; // This will receive the data from the backend

                $scope.loginForm = {};

                $scope.loginForm.username = "";

                $scope.logiForm.password  = "";

/*

 * submit function will send the Ajax request to the server and get the valid username and password

 * for the value entered by the user.

 * NOTE:- The value returned from the Perl API should be JSON format.

 */

                $scope.submit = function() {

                  $scope.names = {};

                  $http.get("http://localhost:5000/login/username/password").

                  success(function (response) {

                      $scope.names = response.user;

                    })

                };
            }]);
#######
RestAPI is returning in the format 

{"user":{"Name":"Ashutosh","Flag":"True"}}

If flag is True then app should redirect to home.html

######
is there any redirect() function in anglarJS ? Do I have to app.service or app.factor or injection mechanism ???

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscribe <at> googlegroups.com.
To post to this group, send email to angular <at> googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Hassan Faghihi | 15 Jun 13:43 2015
Picon

AngularJS, [$rootScope:infdig] on $apply, or View Update On Next Action

Dear sir,

I'm tring to create angular base application joined with .Net MVC & SignalR...

First Let Say i'm new to this world of angular, and even JS framework, and not totally familiar with even JS it self, so it may not be an issue in angular, in other hand it may.

What i'm tring to do is to Use this sample, change it's base structure from JQuery to Angularjs... and in the end change it's data structure, customize it, add and remove feature, and so on

I also create a model, not sure when should i do this, so i did it all on $scope, and create a variable Named ChatModel, and put all variable into that...

the incomplete code is in below, comment are places i didn't convert to angular...

Now lets talk about issues, and what came after another...

first, i needed to put my msg into collection, so i add this:

var MessageList=function(){ //Type Message this.values=[]; this.push=function(username, message){ this.values.push({UserName: username, Message: message}); return;//throw exception }; this.get=function(index) { return this.values[index]; } this.toArray = function () { return angular.copy(this.values); } }

So i can store collection of data, as i were unaware of how to create strongly typed, also one with constructor, so i leave it with dynamic variable... so it went like that, and this in my model:

$scope.ChatModel = { Logged: false, Message: '', Login: { UserName: '', UserId: '' }, Messages: new MessageList()//UserName, Message };

and like this in my UI:

<div class="message" data-ng-repeat="x in ChatModel.Messages.toArray()"> <span class="userName">{{x.userName}}</span>: {{x.message}} </div>

but the issue was that the UI wouldn't get update automatically after function call from server...
for example previously i had $scope.ChatModel.Logged as $scope.logged, but even on that conditon the UI needed to be clicked twice to update UI (Show One Panel And Hide Another One).

i read lot about it, and i used apply function, though it didn't worked. finally, today i understand that theapply is $apply. so it start working. So i then wonder if i can omit $apply, and let angular it self detect the issues, and that's when i came across the $watch, since it didn't worked i went to console, and see there are errors: [$rootScope:infdig], and soon i found out the $apply() it self doesn't work properly.

So can any body help?

I put all the code you may require in below of page. please Help Me:

var app = angular.module("chatApp", []); var advanceChatHub = $.connection.advanceChatHub; app.directive('ngEnter', function () { return function (scope, element, attrs) { element.bind("keydown keypress", function (event) { if (event.which === 13) { scope.$apply(function () { scope.$eval(attrs.ngEnter); }); event.preventDefault(); } }); }; }); app.controller("chatCtrl", ['$scope', function($scope) { //Chat Ctrl 1 / Full Function var MessageList=function(){ //Type Message this.values=[]; this.push=function(username, message){ this.values.push({UserName: username, Message: message}); return;//throw exception }; this.get=function(index) { return this.values[index]; } this.toArray = function () { return angular.copy(this.values); } } $scope.ChatModel = { Logged: false, Message: '', Login: { UserName: '', UserId: '' }, Messages: new MessageList()//UserName, Message }; //$scope.$watchCollection(function(scope) { // return scope.ChatModel.Messages.values; // }, // function(newVal, oldVal, scope) { // if (oldVal.UserName === newVal.UserName && oldVal.Message === newVal.Message) { // console.log("change"); // } // }, true //); $scope.RegisterClientMethod = function(advanceChatHub) { // Calls when user successfully logged in advanceChatHub.client.onConnected = function(id, userName, allUsers, messages) { $scope.ChatModel.Logged = true; $scope.ChatModel.Login.UserId = id; $scope.ChatModel.Login.UserName = userName; //Add All Users var i; for (i = 0; i < allUsers.length; i++) { $scope.AddUser(advanceChatHub, allUsers[i].ConnectionId, allUsers[i].UserName); } for (i = 0; i < messages.length; i++) { $scope.AddMessage(messages[i].UserName, messages[i].Message); } $scope.$apply(); } advanceChatHub.client.onNewUserConnected = function(id, name) { $scope.AddUser(advanceChatHub, id, name); } advanceChatHub.client.onUserDisconnected = function(id, userName) { //$('#' + id).remove(); //var ctrId = 'private_' + id; //$('#' + ctrId).remove(); //var disc = $('<div class="disconnect">"' + userName + '" logged off.</div>'); //$(disc).hide(); //$('#divusers').prepend(disc); //$(disc).fadeIn(200).delay(2000).fadeOut(200); } advanceChatHub.client.messageReceived = function(userName, message) { $scope.AddMessage(userName, message); } advanceChatHub.client.sendPrivateMessage = function(windowId, fromUserName, message) { //var ctrId = 'private_' + windowId; //if ($('#' + ctrId).length == 0) { // createPrivateChatWindow(chatHub, windowId, ctrId, fromUserName); //} //$('#' + ctrId).find('#divMessage').append('<div class="message"><span class="userName">' + fromUserName + '</span>: ' + message + '</div>'); //// set scrollbar //var height = $('#' + ctrId).find('#divMessage')[0].scrollHeight; //$('#' + ctrId).find('#divMessage').scrollTop(height); } } $scope.Events = { btnStartChat: function() { var name = $scope.ChatModel.Login.UserName; if (name.length > 0) { advanceChatHub.server.connect(name); } else { alert("Please enter name"); } }, btnSendMsg: function() { var msg = $scope.ChatModel.Message; if (msg.length > 0) { var userName = $scope.ChatModel.Login.UserName; advanceChatHub.server.sendMessageToAll(userName, msg); $scope.ChatModel.Message = ''; } }, txtNickName: function () { angular.element('#btnStartChat').trigger('click'); }, txtMessage: function () { angular.element('#btnSendMsg').trigger('click'); } }; $scope.AddUser = function(advanceChatHub, id, name) { //var userId = $scope.userId; //var code = ""; //if (userId == id) { // code = $('<div class="loginUser">' + name + "</div>"); //} //else { // code = $('<a id="' + id + '" class="user" >' + name + '<a>'); // $(code).dblclick(function () { // var id = $(this).attr('id'); // if (userId != id) // OpenPrivateChatWindow(chatHub, id, name); // }); //} //$("#divusers").append(code); } $scope.AddMessage = function (userName, message) { $scope.ChatModel.Messages.push(userName, message); var divChatWindows = angular.element('#divChatWindow'); $scope.$apply(); //var divNewMessage = '<div class="message"><span class="userName">' + userName + '</span>: ' + message + '</div>'; //angular.element(divNewMessage).appendTo(divChatWindows); var height = divChatWindows[0].scrollHeight; divChatWindows.scrollTop(height); } $scope.OpenPrivateChatWindow = function(chatHub, id, userName) { var ctrId = 'private_' + id; //if ($('#' + ctrId).length > 0) return; $scope.createPrivateChatWindow(chatHub, id, ctrId, userName); } $scope.createPrivateChatWindow = function(chatHub, userId, ctrId, userName) { //var div = '<div id="' + ctrId + '" class="ui-widget-content draggable" rel="0">' + // '<div class="header">' + // '<div style="float:right;">' + // '<img id="imgDelete" style="cursor:pointer;" src="/Images/delete.png"/>' + // '</div>' + // '<span class="selText" rel="0">' + userName + '</span>' + // '</div>' + // '<div id="divMessage" class="messageArea">' + // '</div>' + // '<div class="buttonBar">' + // '<input id="txtPrivateMessage" class="msgText" type="text" />' + // '<input id="btnSendMessage" class="submitButton button" type="button" value="Send" />' + // '</div>' + // '</div>'; //var $div = $(div); //// DELETE BUTTON IMAGE //$div.find('#imgDelete').click(function () { // $('#' + ctrId).remove(); //}); //// Send Button event //$div.find("#btnSendMessage").click(function () { // $textBox = $div.find("#txtPrivateMessage"); // var msg = $textBox.val(); // if (msg.length > 0) { // chatHub.server.sendPrivateMessage(userId, msg); // $textBox.val(''); // } //}); //// Text Box event //$div.find("#txtPrivateMessage").keypress(function (e) { // if (e.which == 13) { // $div.find("#btnSendMessage").click(); // } //}); //AddDivToContainer($div); } $scope.AddDivToContainer = function($div) { //$('#divContainer').prepend($div); //$div.draggable({ // handle: ".header", // stop: function () { // } //}); //////$div.resizable({ ////// stop: function () { ////// } //////}); } advanceChatHub.connection.start().done(function() { //$scope.registerEvents(hub); }); $scope.RegisterClientMethod(advanceChatHub); } ]);
<at> model dynamic <at> { ViewBag.Title = "title"; Layout = "~/Views/Shared/_Layout.cshtml"; } <at> section headers{ } <at> section scripts{ <script src="~/Scripts/angular.min.js"></script> <script src="~/Scripts/jquery.signalR-2.2.0.min.js"></script> <at> * ReSharper disable Html.PathError * <at> <script src="~/SignalR/Hubs"></script> <at> * ReSharper restore Html.PathError * <at> <script src="~/Scripts/custom/advanceChatSurf.js"></script> } <h2>SignalR Chat Room</h2> <br /> <br /> <br/> <div id="divContainer" data-ng-app="chatApp" data-ng-controller="chatCtrl"> <div id="divLogin" class="login" data-ng-hide="ChatModel.Logged"> <div> Your Name:<br /> <input id="txtNickName" data-ng-enter="Events.txtNickName()" type="text" class="textBox" data-ng-model="ChatModel.Login.UserName" /> </div> <div id="divButton"> <input id="btnStartChat" data-ng-click="Events.btnStartChat()" type="button" class="submitButton" value="Start Chat" /> </div> </div> <div id="divChat" data-ng-show="ChatModel.Logged" class="chatRoom"> <div class="title"> Welcome to Chat Room [<span id='spanUser'></span>] </div> <div class="content"> <div id="divChatWindow" class="chatWindow"> <div class="message" data-ng-repeat="x in ChatModel.Messages.toArray()"> <span class="userName">{{x.userName}}</span>: {{x.message}} </div> </div> <div id="divusers" class="users"> </div> </div> <div class="messageBar"> <input class="textbox" data-ng-enter="Events.txtMessage()" type="text" id="txtMessage" data-ng-model="ChatModel.Message" /> <input id="btnSendMsg" data-ng-click="Events.btnSendMsg()" type="button" value="Send" class="submitButton" /> </div> </div> <input data-ng-model="userId" type="hidden" /> <input data-ng-model="userName" type="hidden" /> </div>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.AspNet.SignalR; namespace ChatSignalR.Hubs { public class AdvanceChatHub : Hub { readonly List<MessageDetail> _currentMessage = new List<MessageDetail>(); readonly List<UserDetail> _connectedUsers = new List<UserDetail>(); public void Hello() { Clients.All.hello(); } #region Proxy Methods public void Connect(string userName) //-->Take User Name From Client Before Application Start // , Store In Hidden / OR / Set it from credentials { var id = Context.ConnectionId; //Get Id And Return It To User Somehow if (_connectedUsers.All(x => x.ConnectionId != id)) // But Only, If Nobody Has This Id { _connectedUsers.Add(new UserDetail //User Not Exist? Then Add Him To Collection { ConnectionId = id, UserName = userName }); //send self information / ConnectedUserLists / Old Messages to User // TODO: 1 --> Never Give Other Users UserId To Other Clients, Says Asp.net Forum, as other can take advantage of it // TODO: 2 --> Limit Messages To Send, As it may become large over time //Send To Caller Clients.Caller.onConnected(id, userName, _connectedUsers, _currentMessage); //Send To Other Clients.AllExcept(id).onNewUserConnected(id, userName); // --> Clients.Others.onNewUserConnected(id, userName); } } public void SendMessageToAll(string userName, string message) { //Get User Name By Connection Id //var id = Context.ConnectionId; //var userInfo = _connectedUsers.FirstOrDefault(w => w.ConnectionId == id); //var userName = (userInfo != null) ? userInfo.UserName : "Unknown Sender"; //Get User By Credential Name //Context.User.Identity.Name //Store Last 100 Messages in Cache AddMessageinCache(userName, message); //Broadcast Message Clients.All.messageReceived(userName, message); } public void SendPrivateMessage(string toUserId /*toUserName*/, string message) { string fromUserId = Context.ConnectionId; var toUser = _connectedUsers.FirstOrDefault(x => x.ConnectionId == toUserId); //Filter By UserName var fromUser = _connectedUsers.FirstOrDefault(x => x.ConnectionId == fromUserId); if (toUser != null && fromUser!=null) { //send to Clients.Client(toUserId).sendPrivateMessage(fromUserId /*UserName*/, fromUser.UserName, message); } } #endregion Proxy Methods #region Hub Events public override System.Threading.Tasks.Task OnDisconnected(bool stopCalled = true) //Ver 2 SignalR { var userInfo = _connectedUsers.FirstOrDefault(x => x.ConnectionId == Context.ConnectionId); { if (userInfo != null) { _connectedUsers.Remove(userInfo); var id = Context.ConnectionId; Clients.All.onDisconnected(id, userInfo.UserName); } } return base.OnDisconnected(stopCalled); } #endregion Hub Events #region Utility #region Cache Management private void AddMessageinCache(string userName, string message) { _currentMessage.Add(new MessageDetail { UserName = userName, Message = message }); if (_currentMessage.Count > 100) _currentMessage.RemoveAt(0); } #endregion Cache Management #endregion Utility } internal class MessageDetail { public string UserName { get; set; } public string Message { get; set; } } internal class UserDetail { public string ConnectionId { get; set; } public string UserName { get; set; } } }

And Just One Simple Controller

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscribe <at> googlegroups.com.
To post to this group, send email to angular <at> googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Gmane