我有一些元素,我想在某些条件下可见.
在AngularJS中我会写
<div ng-show="myVar">stuff</div>
Run Code Online (Sandbox Code Playgroud)
我怎么能在Angular中做到这一点?
有没有人在TypeScript中完成构造函数重载.在语言规范的第64页(v 0.8)中,有一些语句描述构造函数重载,但没有给出任何示例代码.
我现在正在尝试一个非常基本的课堂宣言; 看起来像这样,
interface IBox {
x : number;
y : number;
height : number;
width : number;
}
class Box {
public x: number;
public y: number;
public height: number;
public width: number;
constructor(obj: IBox) {
this.x = obj.x;
this.y = obj.y;
this.height = obj.height;
this.width = obj.width;
}
constructor() {
this.x = 0;
this.y = 0;
this.width = 0;
this.height = 0;
}
}
Run Code Online (Sandbox Code Playgroud)
当使用tsc BoxSample.ts运行时,它会抛出一个重复的构造函数定义 - 这很明显.任何帮助表示赞赏.
我想在angular2项目中使用角度材质自动完成组件.我在模板中添加了以下内容.
<md-input-container>
<input mdInput placeholder="Category" [mdAutocomplete]="auto" [formControl]="stateCtrl">
</md-input-container>
<md-autocomplete #auto="mdAutocomplete">
<md-option *ngFor="let state of filteredStates | async" [value]="state">
{{ state }}
</md-option>
</md-autocomplete>
Run Code Online (Sandbox Code Playgroud)
以下是我的组件.
import {Component, OnInit} from "@angular/core";
import {ActivatedRoute, Router} from "@angular/router";
import {FormControl} from "@angular/forms";
@Component({
templateUrl: './edit_item.component.html',
styleUrls: ['./edit_item.component.scss']
})
export class EditItemComponent implements OnInit {
stateCtrl: FormControl;
states = [....some data....];
constructor(private route: ActivatedRoute, private router: Router) {
this.stateCtrl = new FormControl();
this.filteredStates = this.stateCtrl.valueChanges.startWith(null).map(name => this.filterStates(name));
}
ngOnInit(): void {
}
filterStates(val: …Run Code Online (Sandbox Code Playgroud) 我收到以下错误
未捕获的TypeError:无法读取未定义的属性"setState"
甚至在构造函数中绑定delta之后.
class Counter extends React.Component {
constructor(props) {
super(props);
this.state = {
count : 1
};
this.delta.bind(this);
}
delta() {
this.setState({
count : this.state.count++
});
}
render() {
return (
<div>
<h1>{this.state.count}</h1>
<button onClick={this.delta}>+</button>
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud) 如何使用maven命令行来确定Maven正在拾取哪些settings.xml文件?
我使用的是Angular 2.0.0-alpha.30版本.当重定向到不同的路由,然后刷新浏览器,它显示无法GET /路由.
你能帮我弄清楚这个错误发生的原因吗?
我有一个用ES6编写的项目,webpack作为我的捆绑包.大多数转换工作正常,但当我尝试在任何地方包含装饰器时,我收到此错误:
Decorators are not supported yet in 6.x pending proposal update.
Run Code Online (Sandbox Code Playgroud)
我查看了babel问题跟踪器,并且无法在那里找到任何内容,所以我假设我使用它错了.我的webpack配置(相关位):
loaders: [
{
loader: 'babel',
exclude: /node_modules/,
include: path.join(__dirname, 'src'),
test: /\.jsx?$/,
query: {
plugins: ['transform-runtime'],
presets: ['es2015', 'stage-0', 'react']
}
}
]
Run Code Online (Sandbox Code Playgroud)
我没有任何其他问题,箭头功能,解构所有工作正常,这是唯一不起作用的东西.
我知道我可以一直降级到babel 5.8,我之前有它工作,但如果有任何方法可以在当前版本(v6.2.0)中使用它,那将有所帮助.
有什么区别:
{{::office.name}}
Run Code Online (Sandbox Code Playgroud)
和
{{office.name}}
Run Code Online (Sandbox Code Playgroud)
在angularJS?
尝试使用gulp-babel时出现以下错误:
错误:无法找到相对于目录"/ Users/username"的预设"es2015"
我在全局和本地安装了es2015预设,因此无法理解为什么这会成为一个问题.
下面是我的gulp设置和package.json.
var babel = require('gulp-babel');
var es2015 = require('babel-preset-es2015');
gulp.task('babel', function() {
return gulp.src('./app/main.js')
.pipe(babel({
presets: [es2015]
}))
.pipe(gulp.dest('dist'));
});
Run Code Online (Sandbox Code Playgroud)
的package.json
"devDependencies": {
"babel-preset-es2015": "^6.3.13",
"babel-preset-es2015-node5": "^1.1.1",
"browser-sync": "^2.11.0",
"gulp": "^3.9.0",
"gulp-babel": "^6.1.1",
"gulp-stylus": "^2.2.0"
}
Run Code Online (Sandbox Code Playgroud)
我使用的是node v5.1.0和babel v6.4.0
这是终端输出
在不使用类的情况下,如何在函数无状态组件中使用PropTypes?
export const Header = (props) => (
<div>hi</div>
)
Run Code Online (Sandbox Code Playgroud) javascript ×5
angular ×3
babeljs ×2
ecmascript-6 ×2
reactjs ×2
typescript ×2
angularjs ×1
command-line ×1
constructor ×1
decorator ×1
gulp ×1
maven ×1
maven-2 ×1
node.js ×1
overloading ×1
react-props ×1
settings ×1
webpack ×1