对于这个项目,我只是学习和练习Angular 2.我没有服务器端,并且正在向barchart ondemand api发出API请求 .
我想知道是否有可能绕过cors问题.我对这一切仍然相当新,所以非常感谢宝贝步骤说明!我正在使用http://localhost:8080.
错误信息:( api键已注释掉)
XMLHttpRequest cannot load http://marketdata.websol.barchart.com/getHistory.json?key=MY_API_KEY&symbol=GOOG&type=daily&startDate=20150311000000. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
StockInformationService:
import {Injectable} from 'angular2/core';
import {Http, Headers} from 'angular2/http';
import {Observable} from 'rxjs/Rx';
@Injectable()
export class StockInformationService {
private apiRoot = "http://marketdata.websol.barchart.com/getHistory.json?key=MY_API_KEY&";
constructor (private _http: Http) {}
getData(symbol: string): Observable<any> {
// Tried adding headers with no luck …Run Code Online (Sandbox Code Playgroud) 解决了Eric Martinez在Angular 2中的回答- 动态添加/删除组件,我想限制创建的组件数量.然后删除一个组件后,我试图将该事件发送给父组件,以便父级知道当前创建的组件数.
在这个Plunker中,我将组件数量限制为4,然后我尝试发出一个事件来降低该数量.事件没有发出.如何从动态添加的组件中发出事件?
// dynamic component
@Component({
selector : 'dynamic',
template : `
<div>
Component number {{_idx}} <button (click)="remove()">Remove</button>
</div>`
})
class DynamicCmp {
_ref: ComponentRef;
_idx: number;
@Output lowerIndex = new EventEmitter<any>();
remove() {
this._ref.dispose();
this.lowerIndex.emit(true);
}
}
// Parent container component
@Component({
selector: 'my-app',
template : `
<button (click)="add()">Add new component</button>
<div #location (lowerIndex)="lowerIndex();"></div>
`
})
export class App {
idx: number = 0;
constructor(private _dcl: DynamicComponentLoader, private _e: ElementRef) …Run Code Online (Sandbox Code Playgroud) 针对类似问题的精简堆栈溢出解决方案并没有解决我的问题,因此希望分享我目前遇到的问题以获得帮助调试此问题.
这是一个小小的前言; 我几天前最初安装了minikube/kubectl.我今天继续尝试关注minikube教程,现在遇到了问题.我正在关注minikube入门指南.
我在MacOS上.我的版本:
$ kubectl版本
$ minikube update-context
$ minikube版本
$ minikube ip
$ vboxmanage --version
~/.kube/config
以下是我试图检查响应的一系列命令.
$ minikube开始
$ minikube update-context
$ minikube状态
$ minikube ip
我不知道发生了什么,但再次检查状态返回"Misconfigured".我运行了推荐的命令~/.kube/config,现在$ minikube update-context指向"172.17.0.1".Ping此IP会返回请求超时,100%丢包.双重检查上下文,我仍然在上下文和集群中使用"minikube":
$ kubectl config get-cluster
$ kubectl config get-context
$ kubectl获取pods
$ minikube ip
阅读github问题,我遇到了这个问题:kubernetes#44665.所以...
$ ls/etc/kubernetes
~/.kube/config
$ minikube日志
$ minikube update-context
我不确定如何ping一个https网址,但是如果我ping ip
$ kube ping 192.168.99.103
$ minikube ip
看看kube配置文件...... $ cat ~/.kube/config
$ minikube update-context …
我正在尝试使用*ngFor循环遍历一个对象数组.我意识到我无法使用*ngFor和*ngIf相同的元素,它会返回一个错误.相反,我试图坚持*ngIf列表项的内容.但是现在,我得到了一堆空的列表项,它们正在我的视图页面上创建和显示.
我不想坚持*ngFor我的<ul>元素,因为它会创建一堆<ul>元素,每个元素中都有一个列表项.
我希望你们中的一个人有另一种实现方法.
// AppComponent
// contacts: Contact[]; // An array of `Contact` Objects
<ul>
<li *ngFor="#contact of contacts">
<contact-detail *ngIf="checkList(contact) == true" [contact]="contact"></contact-detail>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
和...
// ContactDetailComponent
<img />
<span>{{contact.name}}</span>
<span>{{contact.email}}</span>
Run Code Online (Sandbox Code Playgroud)
怎么了:
<ul>
<li>
<!--template bindings={}--> // ngIf conditional returned true
<img />
<span>Name1</span>
<span>Email1</span>
</li>
<li>
<!--template bindings={}--> // ngIf conditional returned false
</li>
<li>
<!--template bindings={}--> // false
</li>
<li>
<!--template bindings={}--> …Run Code Online (Sandbox Code Playgroud) 在K&R中,我们引入了char数组来表示字符串.
数组通过引用传递.根据我的理解,我们可以指向数组中的第一个元素(指针?).使用char数组input而不真正定义其值意味着它在数组中设置垃圾数据.(老实说,不确定垃圾数据是什么,可能是空的?).
无论如何,最初将空的char数组传递给function getLength,并设置char数组输入.在我的代码中,我显示了len和char数组input.
在下一个输入中,我getLength再次调用,并传递相同的char数组input.我像以前一样设置值并返回长度.
旧输入如何删除?我不是引用先前存储先前输入的完全相同的数组吗?在我的代码下面,我将展示一个例子.
#include <stdio.h>
#define MAXLINE 1000 /* For allocating storage size for char array */
int getLength(char s[]); /* set char array and return length */
int main(void) {
int len;
char input[MAXLINE];
while ((len = getLength(input)) > 0) {
printf("len = %d\n", len);
printf("string = %s", input);
}
}
int getLength(char s[]) {
int i, c;
for (i = 0; i < MAXLINE …Run Code Online (Sandbox Code Playgroud) 今天我了解到id并决定将其投入使用并进行测试。我知道整数是不可变的,所以 id 应该(?)相同。但当我在提示中进行测试时,我注意到了细微的差异,并想找出其背后的原因。
a = 1
id(a) # 10055552
id(1) # 10055552
a = int(1)
id(a) # 10055552
Run Code Online (Sandbox Code Playgroud)
凉爽的!到目前为止所有检查都已完成。但是之后...
a = 10000
id(a) # 140230117375888
id(10000) # 140230116779920
a = int(10000)
id(a) # 140230116779920
# wait what?? try it again
id(10000) # 140230116780080
# Huh!?
Run Code Online (Sandbox Code Playgroud)
好吧,所以测试一下,我注意到这种行为直到 256 才发生。id 的长度最多为 8 位数字,然后 257 将返回一个更大的 15 位数字长度的 id。所以int类型需要是 8 个字节..测试一下:
a = 256
id(a) # 10063712
id(256) # 10063712
a = 257
id(a) # 140230116780080
id(257) # 140230117375888 …Run Code Online (Sandbox Code Playgroud) 所以,继续这篇文章:ArrayList.clear()和ArrayList.removeAll()有什么区别?......在某些情况下,实际上更好地使用removeAll()而不是clear()吗?
另外,要添加到这个问题,如果我知道我正在清除一个的所有内容ArrayList,是否可以将其设置为新的ArrayList?
ArrayList myList = new ArrayList<String>();
myList.add("a");
myList.add("b");
// instead of using: myList.clear();
myList = new ArrayList<String>()
Run Code Online (Sandbox Code Playgroud)
如果以上情况可以,再次,为什么使用clear()vs设置为新的ArrayList?创建一个新的空ArrayList比O(n)快.
有没有一种方法可以对此标头仅使用一个define语句,而无需将类似于函数的宏更改为函数?
my.h 文件:
#ifndef MY_H
#define MY_H
#define MIN(x, y) ((x) > (y) ? (y) : (x))
#endif
Run Code Online (Sandbox Code Playgroud)
例如,我可以对常量执行以下操作:
pi.h 文件:
#ifndef PI
#define PI 3.14159
#endif
Run Code Online (Sandbox Code Playgroud)
我也意识到以下帖子中关于使用类似函数的宏的警告:https : //stackoverflow.com/a/15575690/4803039
我只想看看是否有更优化/重构的方法。#define当标头主体仅包含一个#define语句本身时,似乎似乎很奇怪地包含一个定义标头主体其余部分的附加语句。
angular ×3
c ×2
cors ×1
header ×1
java ×1
kubernetes ×1
minikube ×1
python ×1
python-3.x ×1
webpack ×1