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

JavaScript

 
GeneralRe: JavaScript or TypeScript: which one to really dig into? Pin
Foothill17-Jul-17 8:31
professionalFoothill17-Jul-17 8:31 
GeneralRe: JavaScript or TypeScript: which one to really dig into? Pin
Kornfeld Eliyahu Peter17-Jul-17 8:41
professionalKornfeld Eliyahu Peter17-Jul-17 8:41 
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 
thanks for your link. few days back i could simulate the same with a example which i like to share here.

i being able to create a small program which can tell me the factory is singleton. so here is the program code
C#
<div ng-app="myApp">
<div ng-controller="FirstCtrl">
  <br>Input is : {{data.firstName}}
  <button ng-click="setData()">setData</button>
</div>
<hr>

<div ng-controller="SecondCtrl">
  Input should also be here: {{data.firstName}}
  <button ng-click="getData()">getData</button>
</div>
</div>

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 ){
$scope.setData = function() {
        Data.FirstName='Tridip';
    };
});

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

$scope.getData = function() {
        alert('get data '+Data.FirstName)
    };
});


i being able to create a small program which can tell me the service is also singleton. so here is the program code
C#
<div ng-app="myApp">
<div ng-controller="FirstCtrl">
  <br>Input is : {{data.firstName}}
  <button ng-click="setData()">setData</button>
</div>
<hr>
<div ng-controller="SecondCtrl">
  Input should also be here: {{data.firstName}}
  <button ng-click="getData()">getData</button>
</div>
</div>

var myApp = angular.module('myApp', []);
myApp.service('Data',function(){

  var FirstName='';
  this.setData=function(FirstName){        
       this.FirstName=FirstName;
  };

  this.getData=function(){
    return FirstName;
  };

});

// Step 1 Controller
myApp.controller('FirstCtrl', function( $scope, Data ){
$scope.setData = function() {
        Data.setData('Mama');
    };
});

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

$scope.getData = function() {
        alert('get data '+Data.FirstName)
    };
});

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 
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 

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.