更新:2018年12月(参见'Aniket'回答)
使用Angular CLI 6,您需要使用构建器,因为不推荐使用ng eject,很快就会在8.0中删除它
更新:2018年6月:Angular 6不支持ng弹出**
更新:2017年2月:使用ng弹出
更新:2016年11月:angular-cli现在只使用webpack.您只需要使用npm install -g angular-cli正常安装."我们改变了beta.10和beta.14之间的构建系统,从SystemJS到Webpack."但实际上我只使用angular-cli来结构和文件夹,然后再使用webpack配置
我用这个安装了角度cli:
npm install -g angular-cli@webpack
Run Code Online (Sandbox Code Playgroud)
当我使用angular1和web pack时,我曾经修改过"webpack.config.js"文件来执行所有的任务和插件,但我没有看到使用angular-cli创建的这个项目是谁工作的.这是魔法?
当我这样做时,我看到Webpack正在工作:
ng serve
"Version: webpack 2.1.0-beta.18"
Run Code Online (Sandbox Code Playgroud)
但我不明白angular-cli配置的工作方式......
我安装了Node 8.9.1(在v10.5.0中也出现了同样的问题).
我正在尝试使用npm包中的命名导入 .mjs
import { throttle } from lodash;
Run Code Online (Sandbox Code Playgroud)
我跑:
node --experimental-modules index.mjs
Run Code Online (Sandbox Code Playgroud)
我得到:
SyntaxError:请求的模块'lodash'在ModuleJob._instantiate中没有提供名为'throttle'的导出(internal/modules/esm/module_job.js:80:21)
--experimental-modules应该停止在v10 LTS中进行实验,那么为什么没有更多的模块作者跳上这个潮流呢?
在反应教程中:
https://egghead.io/lessons/javascript-redux-react-todo-list-example-filtering-todos
有扩展的主要组件创建:
class TodoApp extends Component {
render() {
const visibleTodos = getVisibleTodos(
this.props.todos,
this.props.visibilityFilter
);
.
. // Input and Button stuff
.
Run Code Online (Sandbox Code Playgroud)
而另一个组件只是创建一个包含函数的const:
const FilterLink = ({
filter,
children
}) => {
return (
<a href='#'
onClick={e => {
e.preventDefault();
store.dispatch({
type: 'SET_VISIBILITY_FILTER',
filter
});
}}
>
{children}
</a>
)
}
Run Code Online (Sandbox Code Playgroud)
我看到的差异,首先用类创建一个渲染函数,另一个用于发送回模板的返回函数.
有什么区别?我听说将来只允许使用扩展组件?
在构造中定义变量,在模板中使用它们与在getInitialState()函数内定义有什么区别?
在ES6中我可以忘记使用getInitialState()并在构造上移动所有内容吗?
例:
class TodoApp extends Component {
constructor() {
super();
this.test1 = 'hello this is a test';
this.state = { // thanks to @Piotr Berebecki,
// i know to define states variable
test2:'this is state test'
}
}
changeTest () {
this.state.test2 = 'my new state test';
}
render() {
return (
<div>
<button onClick={this.changeTest}>change</button>
Test:{this.test1}
<br/>State Test:{this.test2}
</div>
);
}
}
ReactDOM.render(
<TodoApp />,
document.getElementById('app')
);
Run Code Online (Sandbox Code Playgroud) 我不知道如何从我的模板中打印JSON数据
如果我在模板中使用:template:people: {{people}}或template:people: {{articles}}
总是进入浏览器:
人物:[object Object]
如果我在模板中使用:template:people: {{people.totalrecords}}或template:people: {{articlestotalrecords}}
得到空白值:人:
import {bootstrap} from 'angular2/platform/browser';
import {Component, enableProdMode, Injectable, OnInit} from 'angular2/core';
import {Http, HTTP_PROVIDERS, URLSearchParams} from 'angular2/http';
import 'rxjs/add/operator/map';
import {enableProdMode} from 'angular2/core';
@Injectable()
class ArticleApi {
constructor(private http: Http) {}
getData: string;
seachArticle(query) {
const endpoint = 'http://xdemocrm.com/webservicecrm.php';
const searchParams = new URLSearchParams()
searchParams.set('object', 'account');
searchParams.set('action', 'list');
return this.http
.get(endpoint, {search: searchParams})
.map(res => res.json())
}
postExample(someData) {
return this.http
.post('https://yourEndpoint', JSON.stringify(someData)) …Run Code Online (Sandbox Code Playgroud) 我一直在寻找教程和文件; 但我不明白下面的代码.2个文件中有2段代码; 服务; 和导入服务的文件.
这是服务角度文件(address-local.js)的一部分代码:
export default angular.module('erp.services.addressLocal', [])
.factory('addressLocal', addressLocal)
.name;
/* @ngInject */
function addressLocal($http) {
Run Code Online (Sandbox Code Playgroud)
这是一段文件代码,其中注入了服务(account.js):
import addressLocalService from '../services/address-local';
Run Code Online (Sandbox Code Playgroud)
我的问题是:
导出中的.name方法是什么; 我在网上看到的大多数例子都不使用.name方法
什么是在导出中使用'erp.services.addressLocal'; 在导入时没有使用,只需一个'import addressLocalService'; 什么是完整的文档语法?
/*@ngInject*/,有用吗?
在哪里可以找到关于.name的完整文档或我可以在"导出"中使用的所有方法?它的ES6与Angular混合在一起?
我想验证一个字段并允许其他字段没有验证; 通过示例来验证:"firstname"字段.在我的代码中,当我评论'payload'时,hapi允许我记录任何字段,当我取消注释'payload'时,hapijs不允许我记录任何字段,但我只想通过示例'firstname'验证为'字符串'并且让剩下的字段允许.我计划让变量字段符合数据库配置,所以我只是验证一些固定字段并让我们保存前端控制的另一个变量字段,而不是后端
config: {
validate: {
/* payload: {
firstname: Joi.string(),
lastname: Joi.string()
...anothers fields...
}*/
}
}
Run Code Online (Sandbox Code Playgroud)
更新:感谢Robert K. Bell,我已经调整了解决方案是添加'验证':
config: {
validate: {
options: {
allowUnknown: true
},
payload: {
firstname: Joi.string()
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在做教程反应,视频#24
https://egghead.io/lessons/javascript-redux-passing-the-store-down-explicitly-via-props
组件地图:
TodoApp - > VisibleTodoList - > FilterLink
我只需要知道为什么VisibleTodoList和FilterLink组件中的代码:"const {store} = this.props",这是获取this.props中的第一个元素吗?在我的控制台日志的底部查看每个组件的this.props和store对象.
class VisibleTodoList extends Component {
componentDidMount() {
const { store } = this.props;
this.unsubscribe = store.subscribe(() =>
this.forceUpdate()
);
}
componentWillUnmount() {
this.unsubscribe();
}
render() {
const props = this.props;
const { store } = props;
const state = store.getState();
return (
<TodoList
todos={
getVisibleTodos(
state.todos,
state.visibilityFilter
)
}
onTodoClick={id =>
store.dispatch({
type: 'TOGGLE_TODO',
id
})
}
/>
);
}
}
class FilterLink extends Component { …Run Code Online (Sandbox Code Playgroud) 我有一个http全球服务,它被称为所有服务; 所以我可以通过例子来管理; 错误,警报,变量等.
customers.service.ts
export class CustomersService {
childUrl = environment.apiUrl + 'customers';
constructor(
private http: HttpClient,
private globalService: GlobalService
) {
}
public get(childUrl) {
return this.globalService.get(this.childUrl)
.catch((res: Response) => this.handleError(res));
}
...
private handleError(err) {
return Observable.throw(err);
}
}
Run Code Online (Sandbox Code Playgroud)
global.service.ts
import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
import { environment } from '../../environments/environment';
@Injectable()
export class GlobalService {
url: string,
constructor(private http: HttpClient) {
this.headers = new HttpHeaders()
.set('Content-Type', 'application/json; charset=utf-8') …Run Code Online (Sandbox Code Playgroud) mongodriver有更新符合http方法restful的方法.Moongose中的等价物是什么?
METHOD MongoDriver Detail Mongoose?
PATCH updateOne Partial Update findOneAndUpdate?
PUT replaceOne Whole replacement doc ...
Run Code Online (Sandbox Code Playgroud) angular ×3
reactjs ×2
angular-cli ×1
angularjs ×1
hapijs ×1
joi ×1
json ×1
jwt ×1
mongodb ×1
mongoose ×1
node-modules ×1
node.js ×1
react-redux ×1
redux ×1
typescript ×1
webpack ×1