所以我有一项服务称为TargetServiceim注入其他各种组件.此TargetService具有一个称为对象Targets集合的属性Target.
我的问题是我希望这个集合在路由到另一个视图后仍然存在.我的路由工作正常,但是一旦路由发生变化,服务就会丢失任何变量的内容,本质上,它会重新初始化服务.我的理解是这些注入的服务是可以传递的单身人士?
在以下示例中,在TargetIndex上,单击一个用于填充Targets[]服务(this.targetService.targets = ts;)上的对象的按钮.工作正常,然后我路由到TargetShow页面,然后回到这个索引,现在这个Targets[]属性是空的,当我希望它包含我已经填充的.
我在这里错过了什么?
App.Module
const routes: Routes = [
{ path: '', redirectTo: 'targets', pathMatch: 'full'},
{ path: 'targets', component: TargetIndexComponent },
{ path: 'targets/:id', component: TargetShowComponent }
]
@NgModule({
declarations: [
AppComponent,
TargetComponent,
TargetIndexComponent,
TargetShowComponent
],
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
HttpModule,
RouterModule.forRoot(routes)
],
providers: [TargetService],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
TargetService
@Injectable()
export class TargetService {
public targets: Target[];
constructor(private …Run Code Online (Sandbox Code Playgroud) 我正在玩Angular 2,我遇到了路由器的麻烦.我想在主路由器插座内安装第二个路由器插座.
在第一个路由器插座内,我重定向到主页,我有第二个路由器插座:
<router-outlet name="main"></router-outlet>
Run Code Online (Sandbox Code Playgroud)
这是我没有导入的app.routing.
const appRoutes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'login', component: LoginComponent},
{ path: 'days', component: DaysComponent, outlet: 'main'}
];
export const appRoutingProviders: any[] = [
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
Run Code Online (Sandbox Code Playgroud)
在HomeComponent ngOnInit我有这个
this.router.navigateByUrl('/(main:days)');
Run Code Online (Sandbox Code Playgroud)
但这会导致网络崩溃,并出现以下错误:
未捕获(承诺):错误:找不到加载'DaysComponent'的插座主页
怎么可能在主要的内部有第二个路由器插座?
谢谢.
我有一个有角度的2应用程序,我使用路由器在视图之间导航,就像其他人一样.以下是我的特定组件的路径:
{
path: 'home/view1/:viewID',
component: ViewComponent,
children: [
{ path: 'pane/:paneId/section/:sectionId', component: SectionEditComponent },
{ path: '**', component: ViewEditComponent }
]
},
Run Code Online (Sandbox Code Playgroud)
现在,我在ViewComponent上有两个按钮,为section1和section2加载SectionEditComponent.
Path1:pane/1/section/1
Path2:pane/1/section/2
ViewComponent模板:
<div class="col-md-8" style="background-color: white; height: 100%">
<button (click)="loadPath(1)">Path1</button>
<button (click)="loadPath(2)">Path2</button>
<router-outlet></router-outlet>
</div>
Run Code Online (Sandbox Code Playgroud)
现在,当我从同一ViewComponent中的Path1-> Path2或Path2-> Path1导航时,不会调用ngOnInit(),因此不会加载新路径,即使url实际上根据新的部分ID进行了更改.
这是已知的还是预期的行为?有什么我做错了吗?
我正在开始使用Angular-CLI(beta 22.1)初始化的新Angular应用程序.但是当我将测试数据(5个值)添加到我的图表时,它似乎缩放错误并且只显示前两个值并将它们拉伸到整个图形长度上(见图).
该项目是空白的,不包含任何CSS.
我的app.component.html:
<div>
<canvas baseChart [datasets]="_numbers" [labels]="_labels" [options]="_chartOpt" [colors]="_chartColours" [legend]="_chartLegend" [chartType]="_chartType" width="600px">
</canvas>
<div>
Run Code Online (Sandbox Code Playgroud)
该 app.component.ts
import { Component } from '@angular/core';
import { BaseChartDirective } from "ng2-charts/ng2-charts";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
private _numbers: any[] = [
{
label: "Test",
data: [10,2,6,7] // should cause 4 points in the chart
}
];
private _chartOpt: any = {
responsive: true
};
public _chartColours:any[] = [];
private _labels: string[] = …Run Code Online (Sandbox Code Playgroud) 在PEP 3103中,Guido正在讨论向Python添加一个switch/case语句以及各种思想,方法和对象.他在此发表了这样的声明:
另一个反对意见是,首次使用的规则允许这样的混淆代码:
Run Code Online (Sandbox Code Playgroud)def foo(x, y): switch x: case y: print 42对于未经训练的人(不熟悉Python),这段代码就等同于:
Run Code Online (Sandbox Code Playgroud)def foo(x, y): if x == y: print 42但这不是它的作用(除非它总是被调用与第二个参数相同的值).这已经通过建议不应该允许case表达式引用局部变量来解决,但这有点武断.
我不会认为自己没有训练或不熟悉Python,但没有任何东西跳出来,因为这两个代码块是不同的.
什么是他引用会使这两段代码执行不同?
我有一个列表网格,我试图使用ng2-dragula拖动和交换网格的瓷砖
some.component.html
<md-grid-list rowHeight="200px" id = "cover" >
<md-grid-tile *ngFor="let werbedata of werbedaten"
[class.selected]="werbedata === selectedWerbedata"
[routerLink]="['/flyerdetail',werbedata.artnr]"
[style.background]="'lightblue'" class = "blocks"
[dragula]='"bag-one"'>
<md-list class="example-card">
<md-list-item>Produktname: {{ werbedata.werbetext }}</md-list-item>
<md-list-item>Euro: {{ werbedata.euro }}</md-list-item>
<h3 md-line> Artnr: {{ werbedata.artnr }} </h3>
<p md-line> Werbetext: {{ werbedata.werbetext }} </p>
</md-list>
</md-grid-tile>
</md-grid-list>
Run Code Online (Sandbox Code Playgroud)
some.component.ts
export class FlyerComponent implements OnInit {
werbedaten: WerbeData[];
selectedWerbedata: WerbeData;
constructor( private werbedatenService: WerbeDatenService ){};
...
...
}
Run Code Online (Sandbox Code Playgroud)
我的想法是在Drop事件上交换数据.是否有可以像这样添加到HTML的onDrop事件?
(onDrop) = "swap(data)"然后swap(data:any)在组件类中执行?
或者我必须初始化dragulaservice?是否有更好的交换方式?
我对于棱角分明的我是个新人,我发现这个非常难以跟随.任何提示将不胜感激?
我想在父模块中声明管道并在子模块中使用它.
@NgModule({
// Pipe which I want to declare in all child modules
declarations: [ ThisIsPipe ],
imports: [ ChildModuleOne, ChildModuleTwo],
})
Run Code Online (Sandbox Code Playgroud)
我该如何使用It子模块?
因为如果我宣布它两次我就会收到错误
未捕获错误:类型ThisIsPipe是2个模块声明的一部分:ChildModuleOne和ChildModuleTwo!请考虑将ThisIsPipe移动到导入ChildModuleOne和ChildModuleTwo的更高模块.您还可以创建一个新的NgModule,它导出并包含ThisIsPipe,然后在ChildModuleOne和ChildModuleTwo中导入NgModule.
我想在我的angular2应用程序中显示代码片段。但是我无法在代码标签中粘贴简单的javascript代码。
我总是需要添加第二个花括号,并且必须添加ngNonBindable。但是我不想添加第二个括号。
有没有人解决这个问题?
http://plnkr.co/edit/OzlHLJxgwSvUffryV3e4
这是我的app.component.html:
<h1>Here is the documentation for the model:</h1>
<pre>
<code ngNonBindable>
export model = new Model({
a:1,
b:function(){}
})
</code>
</pre>
Run Code Online (Sandbox Code Playgroud)
用户应看到:
here is the documentation for the model:
export model = new Model({
a:1,
b:function(){}
})`
Run Code Online (Sandbox Code Playgroud) 我正试图用命令模拟慢速网络链接tc.我netem用来模拟延迟和数据包丢失以及htb来模拟窄带宽,但我发现有一个限制选项netem,这个选项有什么作用?它会影响最终带宽吗?
我用Google搜索并在http://manpages.ubuntu.com/manpages/raring/man8/tc-netem.8.html中找到了一些东西
其中说:
将所选选项的效果限制为指示的下一个数据包的数量.
但我仍然无法理解它的作用.
我正在尝试读取单选按钮值 - 以角度2,
的index.html
<input type="radio" id="options1" name="function" value="create">
<input type="radio" id="options2" name="function" value="continue">
Run Code Online (Sandbox Code Playgroud)
index.ts
@Component({
selector: 'function',
templateUrl: './client/components/function/index.html',
styleUrls: ['./client/components/function/index.css'],
providers: [],
directives: [ROUTER_DIRECTIVES]
})
Run Code Online (Sandbox Code Playgroud)
我需要根据是否创建或继续单选按钮值在html中显示div.
我尝试过的:
document.getElementById- checked未检测到属性获取打字稿文件中单选按钮的值.model.function通过model在打字稿中定义a 来读取值.model显然,无法访问变量![(ngModel)]- 也没用.请为此建议一个转机.
angular ×8
javascript ×3
bandwidth ×1
chart.js ×1
dragula ×1
html ×1
import ×1
ng2-dragula ×1
python ×1
templates ×1
typescript ×1