Hi,

I want to create a Single Page Website with good SEO and Performance. It is 
important to me, to request my data from my CMS through AJAX-Calls via 
Routing.

I got the problem, that my Controller cannot access the data I received. I 
created a DataService for sharing, but the result is the same. I cant acces 
through directives. 

Can somebody help me?

Greetings from Nuremberg, Germany

(function() {
          var app = angular.module('myApp', ['ngSanitize', 'ngRoute', 
'ui.router']);

                app.service("DataService", function() {
                var data = 'Empty Value';

                        return {
                               getData: function() {
                                  return data;
                           },
                             setData: function(newData) {
                                   console.log('This is newData: ' + newData
);
                                    data = newData;
                                return data;
                           }
                      };
             });

                app.controller('ServiceCtrl', ['$scope', 'DataService', 
function ($scope, DataService) {
                       $scope.test = DataService.getData();
                   console.log('Why is this empty? ' + $scope.test);
              }]);

                app.config(function($stateProvider, $urlRouterProvider, 
$locationProvider) {
                   //$locationProvider.html5Mode(true);
                   $locationProvider.hashPrefix('!')
                      $urlRouterProvider.otherwise("/");
                     $stateProvider
                         .state('state1', {
                                     url: '/',
                                      template: 'Test Template',
                                     controller: function ($scope, $http, 
DataService) {
                                            DataService.setData("Before 
AJAX");
                                            $http
                                                  .get('/angular/demo/')
                                                 .then(function(result) {
                                                               $scope.pageObj 
= result.data;
                                                          
DataService.setData($scope.pageObj.id);
                                                        console.log('Called 
from Router: ' + DataService.getData());
                                                   });
                                    }
                              });
            });
    })();

-- 
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 http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to