【问题标题】:Ionic web service run every time the page is opened每次打开页面时都会运行 Ionic Web 服务
【发布时间】:2017-10-30 12:39:07
【问题描述】:

我正在使用 Ionic v1,但遇到了问题。这个错误有很多头条新闻。但我找不到适合我的解决方案。

我愿意,

<ion-nav-view name="other" cache-view="false"></ion-nav-view>

$stateProvider.state('app', {
    url: '/app',
    cache: false,
    abstract: true,
    templateUrl: 'templates/menu.html',
    controller: 'AppCtrl'
})

每次打开页面时运行控制器。但是我的网络服务代码只在第一次打开时运行

我的代码:

.controller('PlaylistsCtrl', function($scope, $rootScope, $http, $ionicPopup) {

    $scope.loadingShow();

    console.log("Test"); //Run everytime but $http run only first opened

    $http.get($scope.webServiceUrl + "json_getSharedPicture.php")
        .then(function(response) {
            $scope.loadingHide();
            $rootScope.playlists = response.data;
        });

})

我的离子信息:

global packages:

    @ionic/cli-utils : 1.2.0
    Cordova CLI      : 7.0.1
    Ionic CLI        : 3.2.0

local packages:

    @ionic/cli-plugin-cordova : 1.2.1
    @ionic/cli-plugin-ionic1  : 1.2.0
    Cordova Platforms         : android 6.2.3 ios 4.4.0
    Ionic Framework           : ionic1 1.3.3

System:

    Node       : v6.10.3
    OS         : Windows 10
    Xcode      : not installed
    ios-deploy : not installed
    ios-sim    : not installed

【问题讨论】:

    标签: angularjs node.js ionic-framework


    【解决方案1】:
    If you want to hit your code every time you load that page.
    

    你需要初始化一个函数并调用它

    function onLoad() {
    $http.get($scope.webServiceUrl + "json_getSharedPicture.php")
        .then(function(response) {
            $scope.loadingHide();
            $rootScope.playlists = response.data;
        });
    }onLoad();
    

    【讨论】:

      猜你喜欢
      • 2019-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-06
      • 2016-02-13
      • 1970-01-01
      • 2015-12-29
      • 2023-03-18
      相关资源
      最近更新 更多