我已将我的项目升级到Angular 6,除了.angular-cli.json文件转换外,一切都很顺利.从我跟随的指南,据说这将自动转换它.
npm install -g @ angular/cli
npm install @ angular/cli ng update
@角/ CLI
然而,事实并非如此,因为我还有旧的 .angular-cli.json
有没有办法自动/手动完成?
我想我误解了Observables应该如何使用.我想要输入一个值,当值更改时,它应该发出新值.我认为这就是它们的用途,但是所有教程和文档似乎都没有这样做,但与此同时,我总是看到它们以这种方式应用.例如,当您订阅"FirebaseListObservable"时,以角度为单位,当firebase中的值更改时,它将触发订阅中的快照.我想为我自己的变量做这个.假设我只有一个字符串变量,当它发生变化时,会触发任何订阅.
我会尽力解释它.我想把这个原则应用到我自己的原则上.
正如您所看到的,我正在向标签栏添加"标签".当我添加足够的标签来填充整个标签栏,并且我不断添加更多标签时,这些标签基本上会调整大小以适应div.我不希望他们扩展div或使用滚动条在它们之间移动.我希望他们在div中收缩.你可以在我链接的GIF上看到确切的例子.
它在窗口大小调整时也应该表现相同.
您对如何实现这一点有任何想法吗?我尝试使用JQuery,但是它太多'硬编码',它不适用于调整大小,也不适用于不同的屏幕分辨率.
HTML我想申请:
<div class="l_tabs">
<div>
<ul id="myTab1" class="nav nav-tabs bordered">
<li class="tab-add"></li>
<li class="contentTab"></li>
<li class="contentTab"></li>
<li class="contentTab"></li>
<li class="contentTab"></li>
</ul>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
当我添加新标签时,它会添加此标签
<li class="contentTab"></li>
有什么建议?
最近我从 Safari 切换到 Brave (Safari 有一个可怕的错误 - 当你打开开发工具时,你会从每个站点注销),并且我尝试在 CORS 禁用模式下运行它。
我尝试修改通常用于 Chrome 的命令,但每次尝试都不成功:
open /Applications/Google\ Chrome.app --args --user-data-dir="/var/tmp/Chrome dev session" --disable-web-security
Run Code Online (Sandbox Code Playgroud)
我的本地 Angular 应用程序正在连接到几个远程服务器,除非我禁用 CORS,否则所有请求都会被阻止 - 并且我无法在服务器上进行任何更改。
我正在设置计算其他两个ngModel的输入值,这似乎工作正常.但是,如果我检查我的ngModel,它根本不会改变.让我演示给你看:
<ion-item>
<ion-label>Total price: {{product.totalPrice}}</ion-label>
<ion-input
type="number"
[value]="product.quantity * product.price"
[(ngModel)]="product.totalPrice"
[ngModelOptions]="{ standalone: true }"></ion-input>
</ion-item>
Run Code Online (Sandbox Code Playgroud)
所以这里{{product.totalPrice}}显示初始值,这很好.如果我手动更改输入,更改将反映在表达式上,这也没关系.但是这个输入将是只读的,它将由changin另外两个输入设置.当我更改它们时,我看到输入上的值正在更新,但不是标签中的表达式.那有什么不对?
这真的很奇怪,因为输入GETS UPDATED中的值,而不是表达式{{product.totalPrice}},我想这个值正在更新,因为其他字段是,但这些值更改从未实际触及ngModel
顺便说一下,我正在使用Ionic 2
单击父模板中的按钮时是否可以加载子组件?例如,父模板html看起来像:
<button (click)="loadMyChildComponent();">Load</button>
<my-child-component></my-child-component>
Run Code Online (Sandbox Code Playgroud)
我想这样做的原因是因为my-child-component需要一些时间来加载它会减慢一切.因此,我只想在用户点击加载它时加载它.我无法更改父模板结构.它必须在那里.
我想只在点击加载按钮时输入子组件的ngOnInit.
我的应用程序包含2个页面,分别称为login,home以及其他延迟加载的页面modules。在app.component.ts中写入条件,以便如果localStorage为空,则应路由到login页面,否则应路由到home页面。然后从首页用户将路由其他延迟加载的模块
app.component.ts
import { Component } from '@angular/core';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { Platform, NavController } from '@ionic/angular';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html'
})
export class AppComponent {
constructor(
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private platform: Platform,
public navCtrl: NavController,
) {
this.initializeApp();
if (localStorage.getItem('token') !== null) {
this.navCtrl.navigateRoot('/home');
} else {
this.navCtrl.navigateRoot('/login');
}
} …Run Code Online (Sandbox Code Playgroud) I have a button on tag with text "Unfreeze". I want to toggle it to "Freeze" on click on the button. Here is ny code:
<a class="btn btn-primary full-width" (click)="clickFreeze($event)">
<i class="fa fa-plus-circle"></i>Unfreeze</a>
private clickFreeze(event) {
console.log("event.srcElement.childNodes[1].textContent", event.srcElement.childNodes[1].textContent);
if(event.srcElement.childNodes[1].textContent =='Unfreeze'){
event.srcElement.innerText="Freeze and Save";
} else if(event.srcElement.innerText =='Freeze and Save'){
event.srcElement.innerText="Unfreeze";
}
}
Run Code Online (Sandbox Code Playgroud)
For some reason it does not work. event.srcElement.childNodes[1].textContent is equal to "Unfreeze" when I console it but it does not enter the if loop.
我正在尝试formGroup根据特定条件在控件中添加和删除验证器。
当我更新formGroup.updateValueAndValidity()整个表单的验证器时,它没有更新,好像我专门申请每个控件,即formGroup.get('formControl').updateValueAndValidity(),它正在工作,但我必须为每个控件编写,我希望这不是正确的方法。我究竟做错了什么?
if (data == 'x') {
this.myForm.get('control2').setValue(null);
this.myForm.get('control2').setValidators(Validators.nullValidator);
this.myForm.get('control1').setValidators(Validators.required);
} else if (data == 'y') {
this.myForm.get('control1').setValue(null);
this.myForm.get('control1').setValidators(Validators.nullValidator);
this.myForm.get('control2').setValidators(Validators.required);
}
this.myForm.get('control1').updateValueAndValidity();
this.myForm.get('control2').updateValueAndValidity();
Run Code Online (Sandbox Code Playgroud)
这是有效的,但是,
this.myForm.updateValueAndValidity();
Run Code Online (Sandbox Code Playgroud)
这是行不通的。
typescript form-control angular formgroups angular-validator
假设有一个简单的框架来显示弹出窗口:
@Component(
selector: 'popup-host',
template: '''
<div class="popup-container">
<ng-template #popupRef></ng-template>
</div>
''',
styles: ['.popup-container { position: absolute; top: 100; left: 100; z-index: 100; }'],
)
class PopupContainerComponent {
final PopupController _controller;
final ComponentLoader _loader;
PopupContainerComponent(this._controller, this._loader);
void ngOnInit() {
_controller.container = this;
}
@ViewChild('popupRef', read: ComponentRef)
ComponentRef popupRef;
void render(PopupConfig config) {
final componentRef = _loader.loadNextTo(config.factory, popupRef);
if (componentRef.instance is HasValueSetter) {
componentRef.instance.value = config.value;
}
}
}
@Injectable()
class PopupController {
PopupContainerComponent _container;
set container(PopupContainerComponent container) => _container = …Run Code Online (Sandbox Code Playgroud) angular ×7
typescript ×4
javascript ×3
html ×2
angular-dart ×1
brave ×1
css ×1
ecmascript-6 ×1
form-control ×1
formgroups ×1
ionic2 ×1
jquery ×1
ngmodel ×1
observable ×1
rxjs ×1
tabs ×1