我正在使用Ionic平台的SQLStorage.remove函数返回一个promise.在我的代码中,我需要删除多个值.当这些都完成后,我需要执行一些代码.
我如何等待所有这些然后执行回调函数?
码:
removeAll() {
this.storage.remove(key1);
this.storage.remove(key2);
this.storage.remove(key3);
}
Run Code Online (Sandbox Code Playgroud)
嵌套所有是一个坏习惯,所以我正在寻找一个体面的解决方案:)
removeAll() {
return this.storage.remove(key1).then(() => {
this.storage.remove(key2).then(() => {
this.storage.remove(key3);
});
});
};
Run Code Online (Sandbox Code Playgroud) 我有以下bash脚本,对于找到的每个图像重复.它需要迭代所有html,css和js文件,并替换该文件中所有出现的图像.
for image in app/www/images-theme-dark/*.png
do
echo "installing icon" $image
# extract filename from iconpath
iconfile=$(basename $image)
iconPath="images/"$(basename $image)
# replace paths in all files containing icon paths
find app/www -type f \( -name "*.html" -or -name "*.css" -or -name "*.js" \
-or -name "*.appcache" \) \
-exec sed -i '' -e 's|$iconPath|images-theme-dark/$iconfile|g' "{}" \;
done
Run Code Online (Sandbox Code Playgroud)
但是当我运行脚本时sed给出:
sed: can't read : No such file or directory
在StackOverflow上我发现sed:无法读取:没有这样的文件或目录但是我已经有了引号{} …
从Angular2访问全局服务,而不是在每个构造函数中都包含它我已经抓住了代码并将其稍微修改为:
@Injectable()
export class ApiService {
constructor(public http: Http) {}
get(url: string) {
return http.get(url);
}
}
@Injectable()
export abstract class BaseService {
constructor(protected serv: ApiService) {}
}
@Injectable()
export class MediaService extends BaseService {
// Why do we need this?
constructor(s: ApiService) {
super(s)
}
makeCall() {
this.serv.get("http://www.example.com/get_data")
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试运行此代码时,我在控制台中收到错误:
NoProviderError {message:"没有ApiService的提供者!(App - > MediaService - > ApiService)",堆栈:"错误:DI异常↵
我创建了一个Plunkr,其代码位于https://plnkr.co/edit/We2k9PDsYMVQWguMhhGl
有谁知道导致此错误的原因是什么?
如果我有一个构造函数 Quo
var Quo = function (string) {
this.status = string;
};
Run Code Online (Sandbox Code Playgroud)
然后用一个新的对象 var myQuo = new Quo("confused");
会有什么区别:
Quo.get_status = function () {
return this.status;
};
Run Code Online (Sandbox Code Playgroud)
和
Quo.prototype.get_status = function () {
return this.status;
};
Run Code Online (Sandbox Code Playgroud) 我为Angular 2创建了一个服务:
import {Injectable} from "angular2/core";
import {Http} from "angular2/http";
import {TaskModel} from "./tasks.model"
@Injectable()
export class TasksDataService {
tasks:Array<any>;
constructor(http:Http) {
this.tasks = [
new TaskModel("Dishes"),
new TaskModel("Cleaning the garage"),
new TaskModel("Mow the grass")
];
}
getTasks():Array<any> {
return this.tasks;
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行我的程序时,浏览器会显示:
system.src.js:1049 GET http://localhost:3000/angular2/http.js 404 (Not Found)
我查找了教程,它们以相同的方式包含angular2/http.有谁看到出了什么问题?
当我在Angular2中发出put请求时,我在响应中收到了预期的set-cookie.但是我的浏览器(尝试过Chrome和Firefox)都拒绝设置cookie.
相反,当我使用Angular 1应用程序调用同一 API端点时,cookie被正确设置.
响应标头是:
Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:http://example.com
Allow:GET, PUT, HEAD, OPTIONS
Content-Type:application/json
Date:Thu, 28 Jan 2016 14:41:38 GMT
P3P:policyref="http://www.example.com/p3p.xml", CP="NON DSP COR CURa TIA"
Server:WSGIServer/0.1 Python/2.7.6
Set-Cookie:sessionid=994wl49qfsizog5bqmt57sgx9q2toa25; expires=Mon, 28-Mar-2016 14:41:37 GMT; Max-Age=5183999; Path=/
Set-Cookie:csrf=u7UQhpAphTsGYKRU6jFlLFt6NoYAhNMS; Domain=api.example.com; expires=Thu, 26-Jan-2017 14:41:38 GMT; Max-Age=31449600; Path=/
Vary:Accept, Cookie
Run Code Online (Sandbox Code Playgroud)
后端在Django 1.8中编程.
有没有人经历过同样的事情或有建议如何解决这个问题?
我有一个 Flutter 项目,它显示带有用户位置的地图。
当通过 USB 连接时,该应用程序可以在物理 Android 和 iOS 设备上正常运行。
如果 iOS 上没有连接 USB 电缆,应用程序启动时会立即崩溃。在 Android 上这不是问题。
我用 Ionic/Angular 制作的其他应用程序没有这个问题。我的应用程序是否尝试连接 XCode 中的某些调试器?或者也许是我错过的另一个设置?
我在Android手机中配置了VPN连接.现在我想通过一个小部件连接这个VPN.如何以编程方式启动连接?大多数代码假设还没有VPN设置,但这不是我要找的地方.我特别关注连接到已配置VPN的代码.
在http://code.google.com/p/android/issues/detail?id=8915上,我找到了以下代码:
VpnService service = context.getSystemService(VPN_SERVICE);
VpnProfile profile = VpnProfile.create(L2TP_PROFILE);
profile.setName(myServerName);
profile.setServerName(myServerAddress);
profile.setRouteList(“192.168.1.0/255.255.255.0,192.168.10.0/255.255.255.0”);
service.connect(profile, myUserName, myPassword);
service.setNotificationIntent(myIntent);
Run Code Online (Sandbox Code Playgroud)
这配置了一个新的VPN.我只想连接现有的VPN.
这个页面http://developer.android.com/reference/android/net/VpnService.html描述了如何实现自己的VPN服务,这也不是我想要的.
在Angular2网站上有一个使用Jasmine在浏览器中进行单元测试的示例:https://angular.io/docs/ts/latest/testing/first-app-tests.html
虽然这样可行,但使用Karma从命令行运行相同的测试会很不错.我尝试了很多配置,但它们都不适用于Angular2,SystemJs,Typescript,Karma,Jasmine的组合.
http://twofuckingdevelopers.com/2016/01/testing-angular-2-with-karma-and-jasmine/ 本教程使用CommonJS,我试图用SystemJS替换它,导致错误并且找不到lib.
当我尝试https://github.com/juliemr/ng2-test-seed的配置时,会抛出如下错误:
25 01 2016 16:19:57.489:WARN [web-server]: 404: /angular2/http
25 01 2016 16:19:57.493:WARN [web-server]: 404: /base/app/angular2/components/cities/cities.data.srv
25 01 2016 16:19:57.494:WARN [web-server]: 404: /base/app/angular2/components/cities/city
25 01 2016 16:19:57.695:WARN [web-server]: 404: /base/app/angular2/components/cities/city.model
25 01 2016 16:19:57.703:WARN [web-server]: 404: /base/app/angular2/pipes/init-caps-pipe
25 01 2016 16:19:57.717:WARN [web-server]: 404: /base/app/angular2/pipes/init-caps/init-caps.pipe
Run Code Online (Sandbox Code Playgroud)
有没有人使用Angular2,Typescript,Karma,Jasmine命令行测试的工作示例?