Hi wisdom,

What did you get the error from this code.? And Exactly, What you want to
get results?


On Tue, Jun 14, 2016 at 5:09 PM, <[email protected]> wrote:

> <!-- Hello, how to fix that below code.Thanks in advance  -->
>
> <!--
> http://stackoverflow.com/questions/18880737/how-do-i-use-rootscope-in-angular-to-store-variables
> -->
> <!DOCTYPE html>
> <html>
> <script src="
> http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js
> "></script>
> <body ng-app="myApp">
>
> <div ng-controller="Ctrl1">
> <h2>Ctrl1 - List</h2>
> <ul>
> <li ng-repeat="item in list()">{{item}}</li>
> </ul>
> </div>
> <hr />
> <div ng-controller="Ctrl2">
> <h2>Ctrl2 - Add</h2>
> <form ng-submit="add(newItem); newItem = '';">
> <input type="text" placeholder="new item..." ng-model="newItem">
> <br />
> <input class="btn" type="submit">
> </form>
> </div>
>
> <script>
> var app = angular.module('myApp', []);
>
> app.factory('items', function() {
> var items = [];
> var itemsService = {};
> itemsService.add = function(item) {
> items.push(item);
> };
> itemsService.list = function() {
> return items;
> };
> return itemsService;
> });
>
> function Ctrl1($scope,items) {
> $scope.list = items.list;
> }
>
> function Ctrl2($scope, items) {
> $scope.add = items.add;
> }
> </script>
>
> <p>Notice that controller's color variable does not overwrite the
> rootScope's color value.</p>
> </body>
> </html>
>
>
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Thanks & Regards,
Sitharthan V K

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to