0

Hi I am newbie to Angular, Ionic. Trying to learn with practice. I have a contoller on my controllers file something like that:

And I have a content pages which all of them runs this controller. Content is something like this:

.controller('GuideCtrlx', ['$scope', '$http', function($scope, $http) {
    var city = "London";
    $http.jsonp("https://en.wikipedia.org/w/api.php?format=json&action=parse&page=" + city + "&prop=text&section=0&callback=JSON_CALLBACK").
    success(function JSON_CALLBACK(data) {
        //stuff goes here
    })
}])
<ion-view title="Cart" id="page2" style="">
    <ion-content padding="true" class="has-header">
        {{ }}
    </ion-content>
</ion-view>

I want to call controller function on every page with different city name to get data. Tried to add ng-init to <ion-content not worked. I have two questions. 1. How to pass value to controller function from a content page mentioned above? 2. How to show content only after getting function result?

Any help will be appreciated.

2
  • Your API endpoint is not JSONP. Please take a look at the documentation mediawiki.org/api/rest_v1 Commented Feb 19, 2017 at 9:38
  • Does it matters? It works. Commented Feb 19, 2017 at 9:51

1 Answer 1

1

As per your logic you can try like this

Controller

    .controller('GuideCtrlx', ['$scope', '$http', function($scope,   $http) {
        // var city = "London";
        $scope.getValue = function(city){

            $http.jsonp("https://en.wikipedia.org/w/api.php?format=json&action=parse&page="+city+"&prop=text&section=0&callback=JSON_CALLBACK").
            success(function JSON_CALLBACK(data) {
                $scope.values = data;

      //stuff goes here

   })
            }

View 1 (here city is London)

<ion-view title="Cart" id="page2" style="" ng-init="getValue('London')">
  <ion-content padding="true" class="has-header">
    {{values}}
  </ion-content>
</ion-view>

View 2 (here city is New York)

<ion-view title="Cart" id="page2" style="" ng-init="getValue('New York')">
  <ion-content padding="true" class="has-header">
    {{values}}
  </ion-content>
</ion-view>
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.