Click here to Skip to main content
15,910,981 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: JavaScript or TypeScript: which one to really dig into? Pin
Foothill17-Jul-17 8:51
professionalFoothill17-Jul-17 8:51 
AnswerRe: JavaScript or TypeScript: which one to really dig into? Pin
Leng Vang24-Jul-17 6:44
Leng Vang24-Jul-17 6:44 
AnswerRe: JavaScript or TypeScript: which one to really dig into? Pin
Anjali Kapoor1-Aug-17 1:50
Anjali Kapoor1-Aug-17 1:50 
QuestionAngularJS: How to prove that service and factory is singleton Pin
Mou_kol12-Jun-17 22:29
Mou_kol12-Jun-17 22:29 
AnswerRe: AngularJS: How to prove that service and factory is singleton Pin
Afzaal Ahmad Zeeshan12-Jun-17 22:55
professionalAfzaal Ahmad Zeeshan12-Jun-17 22:55 
GeneralRe: AngularJS: How to prove that service and factory is singleton Pin
Mou_kol15-Jun-17 2:53
Mou_kol15-Jun-17 2:53 
QuestionHow do I define constructor in service and factory in Angular? Pin
Mou_kol12-Jun-17 3:37
Mou_kol12-Jun-17 3:37 
QuestionAngularJS: Why people prefer factory to share data between controllers Pin
Mou_kol12-Jun-17 3:36
Mou_kol12-Jun-17 3:36 
i am new in angular. so trying to know how to share data between two controller and search google. i visited few pages and found most of the time people use factory to share data. i just like to know can't we do it by service instead of factory ?
1st example
C#
<div ng-controller="FirstCtrl">
  <input type="text" ng-model="data.firstName">
  <br>Input is : {{data.firstName}}
</div>
<hr>
<div ng-controller="SecondCtrl">
  Input should also be here: {{data.firstName}}
</div>

myApp.factory('MyService', function(){
  return {
    data: {
      firstName: '',
      lastName: ''
    },
    update: function(first, last) {
      // Improve this method as needed
      this.data.firstName = first;
      this.data.lastName = last;
    }
  };
});

// Your controller can use the service's update method
myApp.controller('SecondCtrl', function($scope, MyService){
   $scope.data = MyService.data;

   $scope.updateData = function(first, last) {
     MyService.update(first, last);
   }
});


2nd example
C#
var myApp = angular.module('myApp', []);

myApp.factory('Data', function(){

    var service = {
        FirstName: '',
        setFirstName: function(name) {
            // this is the trick to sync the data
            // so no need for a $watch function
            // call this from anywhere when you need to update FirstName
            angular.copy(name, service.FirstName); 
        }
    };
    return service;
});


// Step 1 Controller
myApp.controller('FirstCtrl', function( $scope, Data ){

});

// Step 2 Controller
myApp.controller('SecondCtrl', function( $scope, Data ){
    $scope.FirstName = Data.FirstName;
});


examples are taken from this url https://stackoverflow.com/questions/21919962/share-data-between-angularjs-controllers

please guide me.
AnswerRe: AngularJS: Why people prefer factory to share data between controllers Pin
onelopez12-Jun-17 5:41
onelopez12-Jun-17 5:41 
QuestionHow to write the handler for buttons using JQUERY Pin
Alex Can Work2-Jun-17 7:20
Alex Can Work2-Jun-17 7:20 
GeneralRe: How to write the handler for buttons using JQUERY Pin
ZurdoDev13-Jun-17 1:35
professionalZurdoDev13-Jun-17 1:35 
AnswerRe: How to write the handler for buttons using JQUERY Pin
John C Rayan19-Jun-17 3:51
professionalJohn C Rayan19-Jun-17 3:51 
AnswerRe: How to write the handler for buttons using JQUERY Pin
Member 1069738612-Sep-17 1:10
Member 1069738612-Sep-17 1:10 
GeneralIT developer for a bank needs opinions about my Javascript for online banking OTP Pin
ArtCollector31-May-17 7:31
ArtCollector31-May-17 7:31 
GeneralRe: IT developer for a bank needs opinions about my Javascript for online banking OTP Pin
OriginalGriff31-May-17 7:37
mveOriginalGriff31-May-17 7:37 
GeneralRe: IT developer for a bank needs opinions about my Javascript for online banking OTP Pin
F-ES Sitecore31-May-17 22:25
professionalF-ES Sitecore31-May-17 22:25 
GeneralRe: IT developer for a bank needs opinions about my Javascript for online banking OTP Pin
OriginalGriff31-May-17 22:48
mveOriginalGriff31-May-17 22:48 
GeneralRe: IT developer for a bank needs opinions about my Javascript for online banking OTP Pin
F-ES Sitecore31-May-17 22:27
professionalF-ES Sitecore31-May-17 22:27 
GeneralRe: IT developer for a bank needs opinions about my Javascript for online banking OTP Pin
OriginalGriff31-May-17 22:48
mveOriginalGriff31-May-17 22:48 
GeneralRe: IT developer for a bank needs opinions about my Javascript for online banking OTP Pin
OriginalGriff31-May-17 22:48
mveOriginalGriff31-May-17 22:48 
GeneralRe: IT developer for a bank needs opinions about my Javascript for online banking OTP Pin
Richard Deeming31-May-17 8:24
mveRichard Deeming31-May-17 8:24 
GeneralRe: IT developer for a bank needs opinions about my Javascript for online banking OTP Pin
Richard MacCutchan31-May-17 22:35
mveRichard MacCutchan31-May-17 22:35 
GeneralRe: IT developer for a bank needs opinions about my Javascript for online banking OTP Pin
OriginalGriff31-May-17 22:49
mveOriginalGriff31-May-17 22:49 
GeneralRe: IT developer for a bank needs opinions about my Javascript for online banking OTP Pin
Richard MacCutchan1-Jun-17 1:01
mveRichard MacCutchan1-Jun-17 1:01 
GeneralRe: IT developer for a bank needs opinions about my Javascript for online banking OTP Pin
OriginalGriff1-Jun-17 1:16
mveOriginalGriff1-Jun-17 1:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.