JavaScript AngularJS : Fetching Service Data

OBJECTIVE

Have Angular access a Service, retreive information, and display Service Information in two different controllers (later these controllers will manipulate this data, independently).

LIVE DEMO http://plnkr.co/edit/pqnt5IHr3N3oUynfbz37?p=preview

index.html

<html ng-app='plunker'>

<head>
  <title>AngularJS - Searching Text</title>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.0-rc.1/angular.min.js"></script>
  <script src="app.js"></script>
</head>

<body>
  <h1>Search & Reverse Text</h1>

  <h2>Original Sentence sent to Service</h2>
  <form>
    <input type='text' ng-model='value' placeholder='insert sentence' />
    <button ng-click='setString(value)'>Set</button>
    <pre>Sentence: {{value}} </pre>
  </form>

  <div ng-controller='myController1'>
    <h2>Controller 1 fetching from Service</h2>
    <pre>{{fetch1}}</pre>
  </div>

  <div ng-controller='myController2'>
    <h2>Controller 2 fetching from Service</h2>
    <pre>{{fetch2}}</pre>
  </div>


</body>

</html>

app.js

var app = angular.module('plunker', []);

/*Service to pass data between controllers */
app.service('passData', function() {
  $scope.stringValue = {};

  $scope.getString = function() {
    return stringValue;
  },

  $scope.setString = function(value) {
    stringValue = value;
  }
});

/* Controller1 catched string from  original sentence */
app.controller('myController1',['passData', function($scope) {
  $scope.fetch1 = passData.getString();
}]);

/*Controller2 catched string from  original sentence */
app.controller('myController2', ['passData', function(scope){
  $scope.fetch2 = passData.getString();
}]);

QUESTIONS

  1. How can I check if the service is catching the original sentence?
  2. Why is it that both {{fetch1}} and {{fetch2}} aren't displaying properly?
  3. Is this a proper use of services interacting with controllers? Are there better ways?
Answer:1

Environment: Visual Studio 2008 SP1, ASP.NET and JavaScript I'm trying to do a quick document.write test but as soon as I add script tags Visual Studio editor doesn't like it. Specifically, the ...

Environment: Visual Studio 2008 SP1, ASP.NET and JavaScript I'm trying to do a quick document.write test but as soon as I add script tags Visual Studio editor doesn't like it. Specifically, the ...

Weird, line one works fine but line 3 give me TypeError: dojo.byId(...).attr is not a function. There is hidden fields that hold all student pair that as <input type="hidden" id="...

Weird, line one works fine but line 3 give me TypeError: dojo.byId(...).attr is not a function. There is hidden fields that hold all student pair that as <input type="hidden" id="...

I am attempting to run a script in a webpage, that should be executed in an <iframe>. Right now I can call a function that is set within the <iframe>.. I'm just having issues running a ...

I am attempting to run a script in a webpage, that should be executed in an <iframe>. Right now I can call a function that is set within the <iframe>.. I'm just having issues running a ...

  1. javascript iframe content
  2. javascript iframe contentwindow
  3. javascript iframe contentdocument
  4. javascript iframe contentdocument is null
  5. javascript iframe content height
  6. javascript iframe content loaded
  7. javascript iframe content change event
  8. javascript iframe content find
  9. javascript iframe contentwindow null
  10. javascript iframe content size
  11. javascript iframe contentwindow restricted
  12. javascript iframe content cross domain
  13. javascript iframe contentwindow postmessage
  14. javascript iframe content change
  15. javascript iframe contentwindow access denied
  16. javascript iframe contentdocument access denied
  17. javascript iframe contentwindow.document
  18. javascript iframe content height cross domain
  19. javascript iframe content type
  20. javascript iframe content parent

I started using html twig in Symfony2 and I got the following problem: function goEditConflict(){ $("#go").on("click", function(){ id = $("#case_number").val(); windows.location = {{ ...

I started using html twig in Symfony2 and I got the following problem: function goEditConflict(){ $("#go").on("click", function(){ id = $("#case_number").val(); windows.location = {{ ...

  1. parsing variable from javascript to php
  2. parsing variable in javascript
  3. parsing variable in java
  4. parsing parameters from url
  5. parsing variable in bash
  6. passing variable in sed
  7. passing variable in jquery
  8. passing variable in mysql
  9. passing variable in informatica
  10. parsing variable in xml