发送请求的角度脚本。以json的形式获得答案。如何定期发送您的询问? 如何使用位于互联网上的应用程序图标图片,收到zhson的数据?`
var app = angular.module('jsbin', ['ngAnimate']);
app.controller('DemoCtrl', function($http,$scope) {
var vm = this;
var temp1=[];
var URL2=[];
var URL = 'http://api.openweathermap.org/data/2.5/forecast/daily';
var showSwitch=false;
var request = {
method: 'GET',
url: URL,
params: {
q: localStorage["var"],
mode: 'json',
units: localStorage["SystemOfNumbers"],
cnt: '7',
appid: '3ac1f68b653ffbf72a5f782420062771'
}
};
var showMe=false;
$scope.myFunc=function() {
$scope.showMe=!$scope.showMe;
}
var range = [];
for(var i=0;i<7;i++) {
range.push(i);
}
$scope.range = range;
$scope.colorFont=function(templiche){
if (templiche>0) return 'red';
else {
return 'blue';
}
}
$http(request)
.then(function(response) {
vm.data = response.data;
vm.URL2="http://openweathermap.org/img/w/"+vm.data.list[0].weather[0].icon+".png";
vm.mmrts=Math.round(vm.data.list[0].pressure* 0.7500);
vm.symbal=localStorage["Symbal"];
}).
catch(function(response) {
vm.data = response.data;
vm.URL2="http://openweathermap.org/img/w/"+vm.data.list[0].weather[0].icon+".png";
vm.symbal=localStorage["Symbal"];
});
}
);
{
"manifest_version" : 2,
"name" : "...",
"short_name" : "...",
"version" : "1.0",
"author" : "...",
"description" : "...",
"icons" : {
"16" : "http://openweathermap.org/img/w/13d.png",
"32" : "http://openweathermap.org/img/w/13d.png",
"48" : "http://openweathermap.org/img/w/13d.png",
"64" : "icons/64x64.png",
"128" : "icons/128x128.png"
},
"content_scripts": [
{
"matches": [ "*://*/*" ],
"js": [ "weather.js" ]
}
],
"background" : {
},
"permissions": [
"storage","activeTab"
],
"browser_action": {
"default_title": "...",
"default_icon": "icons/water.png",
"default_popup": "popup.html"
}
}
并格式化地址图标:“http://openweathermap.org/img/w/ {{item.weather [0] .icon}}。png”
答案 0 :(得分:0)
您可以使用setIcon method动态更改图标。例如:
chrome.browserAction.setIcon({path:'https://example.com/image.png'});
要定期发送请求,您需要创建background page并使用alarm API。