美文网首页
ionic1 常见问题

ionic1 常见问题

作者: 40dd4b561abe | 来源:发表于2018-11-05 11:19 被阅读6次
    屏幕快照 2018-11-05 上午10.52.09.png

    video 标签scr跨域

    .config里的配置
      $urlRouterProvider.otherwise('/app/home');//默认显示页面
      $ionicConfigProvider.backButton.text("");//返回按钮的文字
      $ionicConfigProvider.backButton.previousTitleText(false);
      $sceDelegateProvider.resourceUrlWhitelist([//解决资源跨域
           // Allow same origin resource loads.
           'self',
           // Allow loading from our assets domain.  Notice the difference between * and **.
           'http://172.18.13.51:8100/**']);
    

    一个访问接口service的简单封装

    service.js
    
    angular.module('starter').service('myRequest',['$http','$rootScope', function($http,$rootScope){
        this.homeList = function (obj,params) {
            return this.get('https://randomuser.me/api/',obj);
        }
        this.post = function (url,obj,params) {
            return this.request(url,'POST',obj,params);
        };
        this.get = function (url,obj,params) {
            return this.request(url,'GET',obj,params);
        };
        this.request = function (url,meth,obj,params) {
            $http({
                method:meth,
                url:url,
                params:params
            }).success(function (data) {
                $rootScope.$broadcast(obj,data);
            }).error(function (err) {
                $rootScope.$broadcast(obj,['msg','错误返回']);
    
            });
        };
    
    }]);
    

    在controller里的调用

    .controller('homeCtrl', ['$scope','myRequest', function($scope,myRequest){
      
      myRequest.homeList('homeList');
      $scope.$on('homeList',function (event,data) {
        console.log('wancheng');
      })
    
    }]);
    

    相关文章

      网友评论

          本文标题:ionic1 常见问题

          本文链接:https://www.haomeiwen.com/subject/lnajxqtx.html