在Angular 2中,我们有几种方法可以在模板中创建属性绑定.我可以这样做:
<li *ngFor="#course of courses; #i = index" id="someselector-{{i}}">{{course}}</li>
Run Code Online (Sandbox Code Playgroud)
是否可以使用方形brakets语法获得相同的结果?
<li *ngFor="#course of courses; #i = index" [id]="someselector-i">{{course}}</li>
^^^^^^^
how create string concatenation?
Run Code Online (Sandbox Code Playgroud)
谢谢,G.
我正在编写一个AngularJS组件,我想知道将ngdoc注释添加到组件本身和控制器功能的正确方法是什么.
你有什么例子吗?
我有一组静态数据,一组国家,用于某些组件.这些数据加载到ngOnInit()这些组件中,但我想加载它们只是在我第一次请求数据时(存储是空的).每次我加载组件时我只想使用商店中的数据而不"刷新"它.
如何使用ngrx实现这一目标?
我正在使用效果.这是我的代码的样子:
组件:
export class EditPageComponent implements OnInit {
countries$: Observable<Country[]>
constructor(private store: Store<fromContacts.State>) {
this.countries$ = store.select(fromContacts.getCountriesEntities);
}
ngOnInit() {
this.store.dispatch(new countries.Load());
}
Run Code Online (Sandbox Code Playgroud)
效果:
@Effect()
loadCollection$: Observable<Action> = this.actions$
.ofType(countries.LOAD)
.switchMap(() =>
this.countriesService
.getCountries()
.map((countriesList: Country[]) => {
return new countries.LoadSuccess(countriesList);
})
.catch(error => of(new countries.LoadFail(error)))
);
Run Code Online (Sandbox Code Playgroud)
还原剂:
case countries.LOAD_SUCCESS: {
const countriesList: Country[] = action.payload;
const reducedCountries: { [id: string]: Country } = countriesList.reduce((countrs: { [id: string]: Country }, countr: Country) => {
return Object.assign(countrs, …Run Code Online (Sandbox Code Playgroud) 在我的表单中,我有一个“金额”字段,该字段应始终显示2个十进制数字。因此,例如,如果用户键入3,则应将其转换为3.00。如果他输入3.1234525,则应变为3.12。
为了做到这一点,我依靠onBlur道具。基本上,onBlur我运行一个函数来正确格式化数字,然后尝试在字段上设置新值。
这是我的代码:
import { blur as blurField } from 'redux-form/immutable';
...
const mapDispatchToProps = {
blurField,
};
...
export default connect(mapStateToProps, mapDispatchToProps)(Amount);Run Code Online (Sandbox Code Playgroud)
class AmountContainer extends Component {
props: PaymentMethodPropsType;
formatAmount(event) {
const {
blurField,
} = this.props;
blurField('myForm', 'amount', formatNumber(event.currentTarget.value, 2));
}
/**
* Render method for the component
* @returns {Element<*>} the react element
*/
render() {
const {
t,
amountValue,
} = this.props;
const amountLabel = t('form')('amountLabel');
return (
<Amount
amountLabel={amountLabel}
amountValue={amountValue}
normalize={onlyNumbersDecimals}
onBlur={(event: Event) => this.formatAmount(event)} …Run Code Online (Sandbox Code Playgroud) 我正在查看ngrx repo中定义的example-app:https: //github.com/ngrx/platform/tree/master/example-app
我可以看到该ChangeDetectionStrategy.OnPush属性仅在"容器"组件上设置,而虚拟组件不会覆盖默认的更改检测策略.
任何人都可以解释原因吗?我希望应用程序中的所有组件都能使用 ChangeDetectionStrategy.OnPush
谢谢,
瞎扯
Safari似乎没有在网络检查器工具中记录http重定向。
我处于无法使用http代理(例如Charles)的环境中,所以我想知道是否有任何Safari插件可以做到这一点。
谢谢。
我正在使用controllerAs和bindToController"pattern"在Angular 1.4.12上实现AngularJS指令,以便拥有一个不依赖于$ scope的干净控制器.但是我仍然觉得很难摆脱这些线上的$ scope:
$scope.$on( '$destroy', function() {...} );
$scope.$on( '$stateChangeSuccess', function() {} );
Run Code Online (Sandbox Code Playgroud)
知道如何处理这种情况吗?
谢谢
javascript ×3
angular ×2
angularjs ×2
ngrx ×2
http ×1
ngdoc ×1
redux ×1
redux-form ×1
safari ×1