我正在用ES6和Babel建立一个网站.
在脚本文件中,我需要对服务器上的服务进行ajax调用.为此,我这样做:
fetch('url').then(
response => response.json()
).then(
supervisoryItems => doSomething(supervisoryItems)
)
Run Code Online (Sandbox Code Playgroud)
在谷歌浏览器中这很好用,但它不适用于Firefox或IE(我收到错误fetch is undefined).在Google上搜索我发现这应该解决它:
import promise from 'es6-promise'
promise.polyfill()
Run Code Online (Sandbox Code Playgroud)
可悲的是,它没有改变任何东西,我有同样的问题.有帮助吗?
我正在学习Angular2.我有一个带有变量的组件,它是一个对象.我正在迭代对象的字段,并根据该位置的数据类型,我需要渲染一个不同的组件.在这种情况下,我想要tu渲染,label如果typeof那个位置是一个number如何这不起作用
<div>
<div *ngIf='obj'>
<label *ngFor="let key of keys; let i = index">
<label class='key'>{{key}}:</label>
<label class='number' *ngIf='typeof obj[key] === "number"'>
<!-- label class='number' *ngIf='obj[key] | typeof === "number"' -->
{{ obj[key] }}
</label>
</label>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我还创建了一个管道,以便在typeof打印值时使用哪个,但不在*ngIf中
我有一个React应用程序,我需要使用Redux进行ajax调用(以便学习)到在线服务(异步).
这是我的商店:
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import duedates from './reducers/duedates'
export default applyMiddleware(thunk)(createStore)(duedates);
Run Code Online (Sandbox Code Playgroud)
这是行动:
import rest from '../Utils/rest';
export function getDueDatesOptimistic(dueDates){
console.log("FINISH FETCH");
console.log(dueDates);
return {
type: 'getDueDate',
dueDates
}
}
export function waiting() {
console.log("IN WAIT");
return {
type: 'waiting'
}
}
function fetchDueDates() {
console.log("IN FETCH");
return rest({method: 'GET', path: '/api/dueDates'});
}
export function getDueDates(dispatch) {
console.log("IN ACTION");
return fetchDueDates().done(
dueDates => dispatch(getDueDatesOptimistic(dueDates.entity._embedded.dueDates))
)
}
Run Code Online (Sandbox Code Playgroud)
这是减速器:
export default (state = {}, …Run Code Online (Sandbox Code Playgroud) 我目前正在处理2个项目,当我推送它时,我希望我配置我的本地用户名和电子邮件使用不同的数据.
为此,我一直在更新我的配置,如:
git config --local user.email "namelastname@domain.com"
由于它们是不同的存储库,有没有办法为每个存储库定义本地电子邮件?
也许在.gitconfig?
我正在阅读有关节点的Angular 2 Server侧渲染的内容.
但我找不到一个例子或解释我该怎么做.我需要从服务器渲染一些带有角度的页面,有什么建议吗?
我正在尝试部署一个Web项目,为此,在构建它之前,我需要清除该dist文件夹.
当然我可以添加一个可以运行的脚本,rm -rf dist/*但是一些Windows用户将无法运行它.
是否有一些npm包会删除带有命令的文件夹?
我正在尝试学习Angular 2,所以我做了一些hello world例子.这是我的代码:
boot.ts
import {bootstrap} from 'angular2/platform/browser'
import {AppComponent} from './app.component'
import {DataService} from './app.dataservice'
bootstrap(AppComponent, [DataService]);
Run Code Online (Sandbox Code Playgroud)
的index.html
...
<body>
<hello-world>Loading...</hello-world>
<hello-world>Loading...</hello-world>
</body>
...
Run Code Online (Sandbox Code Playgroud)
app.component.ts
import {Component} from 'angular2/core';
import {DataService} from './app.dataservice'
@Component({
selector: 'hello-world',
template: '<h1>Hello {{ item }}</h1>'
})
export class AppComponent {
items: Array<number>;
item: number;
constructor(dataService: DataService) {
this.items = dataService.getItems();
this.item = this.items[0];
}
}
Run Code Online (Sandbox Code Playgroud)
app.dataservice.ts
export class DataService {
items: Array<number>;
constructor() {
this.items = [1,2,3];
}
getItems() {
return …Run Code Online (Sandbox Code Playgroud) 我正在学习Reactjs,我正在使用一些组件渲染一个简单的页面.其中一个组件是:
class Header extends React.Component {
render(){
return (
<header>
<div class="container">
<Logo />
<Navigation />
</div>
</header>
);
}
}
export default Header
Run Code Online (Sandbox Code Playgroud)
我正在使用Bootstrap CSS我希望div标题内部使用样式container,但是,在构建之后,类已经消失了.
有没有办法强制组件中的属性类?
我正在学习Angular 2.为此,我试着创建基本的例子.
我有一个包含此字符串的变量的类: M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z
我正在尝试将该字符串用作svg元素的参数
只是为了检查:
这个svg有效:
<svg fill="white" height="64" width="64">
<path d="M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z"/>
</svg>
Run Code Online (Sandbox Code Playgroud)
icon模板中的变量包含正确的字符串.我想这样做:
<svg fill="black" height="24" width="24">
<path d={ icon } />
</svg>
Run Code Online (Sandbox Code Playgroud)
并添加"参数d.但我不能让它发挥作用
我正在从Angular JS做一个ajax调用:
var response = $http.post(
'/services/login/?_nochache='+new Date().getTime(),
JSON.stringify(credentials)
);
Run Code Online (Sandbox Code Playgroud)
我正在添加_nocache设置,认为可能是某些缓存或类似的东西.
我也将对象credentials转换为字符串,认为Internet Explorer无法识别该对象.
我真的迷失在这里,在Chrome中调用完美,在IE 10中,服务的响应为空.
是什么导致这个?
该服务返回401,这是好的,因为用户错了,但响应应该(如在其他浏览器中一样),错误字符串表示用户错误,在这种情况下为空.
我正在使用这样的承诺:
promise.then(onLoginOk, onLoginError);
...
function onLoginError(response) {
console.log(JSON.stringify(response));
}
Run Code Online (Sandbox Code Playgroud)
控制台返回
{
"data": null,
"status": -1,
"config": {
"method": "POST",
"transformRequest": [
null
],
"transformResponse": [
null
],
"url": "http://dev.site.com:8000/api/auth/login/",
"data": {
"username": "mail@domain.com",
"password": "password"
},
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json;charset=utf-8"
}
},
"statusText": ""
}
Run Code Online (Sandbox Code Playgroud)
javascript ×7
angular ×4
reactjs ×2
ajax ×1
angularjs ×1
asynchronous ×1
babeljs ×1
deployment ×1
ecmascript-6 ×1
git ×1
github ×1
npm ×1
redux ×1
redux-thunk ×1
typescript ×1