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');
})
}]);
网友评论