2

I am calling rest service in my controller to get the values like first name and last name etc but its not returning any values.

Here is my controller:

myApp.controller('profileController', function ($scope, $http) {

    var url = 'rs/FetchProfile';
    $http.get(url).success(function (response)
    {
        $scope.profiles = response;
        console.log($scope.profiles); //prints nothing       
    }).error(function (response)
    {
        console.log("error", response);
    });
});

The controller is not returning any values. Here is the html code where ng-controller="profileController" is declared inside LoggedIn.hmtl

<div ng-controller="profileController" >
    <div ng-repeat="x in profiles" class="col-lg-4 reduce-left-margin-80">
        <ul style="list-style-type: none;">
            <li>First name and Last name</li>
            <li>position xxxxxxx xxxxxxx</li>
            <li>Company xxxxxx xxx xxxxx</li>
            <li><i class="fa fa-envelope"></i> Email address</li>
        </ul>
    </div>
</div>

My main html page is like this:

<html lang="en" ng-app="myApp">
    <head>
        <title>RTH - Home page</title>
    </head>
    <body>
        <div id="wrap">
            <!--header-->
            <div ui-view="header"></div>
            <!--main content-->
            <div ui-view="content"></div>
        </div>
        <!--footer-->
        <div ui-view="footer"></div>
        <!-- script tags here -->
    </body>
</html>

And stateprovider:

$stateProvider
    .state('first', {
        url: "/first",
        views: {
            header: header,
            content: {
                templateUrl: 'views/HomePage.html',
                controller: function ($scope) {
                }
            },
            footer: footer
        }
    })
    .state('LoggedIn', {
        url: "/LoggedIn",
        views: {
            'header': header,
            'content': {
                temlateUrl: 'views/LoggedIn.html',
                controller: function () {
                }
            },
            'footer': footer
        }
    });
});

Do I have to define second state as well for my profile controller to be called?

16
  • in the $stateProvider, you dont define that it corresponds to 'profileController', you are creating a new controller with controller: function ($scope) {} Commented Jan 1, 2016 at 11:38
  • Have you tried to make rest api call through other tool? Commented Jan 1, 2016 at 11:38
  • 1
    You have to replace "controller; function($scope) { }" with "controller: 'profileController'" Commented Jan 1, 2016 at 11:40
  • @PierreEmmanuelLallemant still the same. Commented Jan 1, 2016 at 11:46
  • @HamletHakobyan Yes I tried with postman(chrome rest plugin) and its returning values on GET request but its not returning any thing in my app Commented Jan 1, 2016 at 11:51

1 Answer 1

1

There's a typo in your router config. It should be templateUrl instead of temlateUrl.

$stateProvider
    .state('profile', {
        url: "/profile",
        views: {
            header: header,
            content: {
                templateUrl: 'views/LoggedIn.html',
                controller: 'profileController'
            },
            footer: footer
        }
    })
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.