我一直在线使用这些教程并创建了一个'ok'SPA数据输入应用程序.
我把它连接到我的WEB API很好,但只构建了一个模型,我的AppModule已经安静了几行.
我正在考虑使用当前的方法,我认为一旦我完成它,AppModule将是一个疯狂的大小,难以阅读,甚至可能更难调试.
我是否可能错过了如何构建Angular2更大应用程序的观点?
我正在努力寻找一个大于1个组件的在线教程/项目供参考.
下面是我的app.module.ts文件夹结构.
我分开我CashMovement,ListComponent并且DataService我会认为这是很好的做法,但再添10个不同的数据服务,并列出与app.module将是漫长的.
在我继续进行任何进一步的工作之前,任何人都应该阅读一些他们可以指向我的建议,或者我理解的建议对个人意见是主观的.
import './rxjs-operators';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { PaginationModule, DatepickerModule, Ng2BootstrapModule, ModalModule, ProgressbarModule, TimepickerModule } from 'ng2-bootstrap/ng2-bootstrap';
import { SlimLoadingBarService, SlimLoadingBarComponent } from 'ng2-slim-loading-bar';
import { AppComponent } from './app.component';
import { DateFormatPipe } from './shared/pipes/date-format.pipe';
import { HighlightDirective } from './shared/directives/highlight.directive'; …Run Code Online (Sandbox Code Playgroud) 有没有办法做以下的事情?
f = (o:{a:x}) {
console.log(o);
console.log(x);
}
f({a:0});
//Should Print:
//{a:0}
//0
Run Code Online (Sandbox Code Playgroud)
获得与此相同的结果.
f = function(o) {
var {a:x} = o;
console.log(o);
console.log(x);
}
f({a:0});
//Prints
//{a:0}
//0
Run Code Online (Sandbox Code Playgroud)
我想解析函数参数中的对象,同时将对象传递给函数,以便可以修改对象.
一个同事和我一直在同一个分支上工作一个星期,不断推/拉变化,突然今天,我点击'拉'看看是否有任何变化我需要拉,我得到一个错误.
顺便提一下,这是源码.错误是这样的:
git -c diff.mnemonicprefix=false -c core.quotepath=false fetch origin
error: cannot lock ref 'refs/remotes/origin/angular_removal': unable to resolve reference 'refs/remotes/origin/angular_removal': reference broken
From https://bitbucket.org/colossus
! [new branch] angular_removal -> origin/angular_removal (unable to update local ref)
Run Code Online (Sandbox Code Playgroud)
我在sourcetree,它有一个内置的终端,但我似乎无法在这里找到解决方案.
为了进入TypeScript的精神,我在我的组件和服务中编写完全类型的签名,这扩展到我对angular2表单的自定义验证函数.
我知道我可以重载一个函数签名,但这要求每个返回类型的参数不同,因为tsc将每个签名编译为一个单独的函数:
function pickCard(x: {suit: string; card: number; }[]): number;
function pickCard(x: number): {suit: string; card: number; };
function pickCard(x): any { /*common logic*/ };
Run Code Online (Sandbox Code Playgroud)
我也知道我可以返回一个类型(如Promise),它本身可以是多个子类型:
private active(): Promise<void|null> { ... }
Run Code Online (Sandbox Code Playgroud)
但是,在angular2自定义表单验证器的上下文中,单个签名(类型的一个参数FormControl)可以返回两种不同的类型:Object带有表单错误,或null指示控件没有错误.
显然,这不起作用:
private lowercaseValidator(c: FormControl): null;
private lowercaseValidator(c: FormControl): Object {
return /[a-z]/g.test(c.value) ? null : { lowercase: this.validationMessages.lowercase };
}
Run Code Online (Sandbox Code Playgroud)
也没做
private lowercaseValidator(c: FormControl): null|Object {...}
private lowercaseValidator(c: FormControl): <null|Object> {...}
Run Code Online (Sandbox Code Playgroud)
(有趣的是,我得到了以下错误,而不是更多信息:
error TS1110: …Run Code Online (Sandbox Code Playgroud) 我一直在阅读一些关于Web组件的教程(本机,没有聚合物).我已经看到了两种注册组件的方法,我对使用什么感到困惑.对于第二个,我实际上在vscode中收到了一个打字稿错误:[ts] Property 'registerElement' does not exist on type 'Document'. Did you mean 'createElement'?
/**
* App
*/
export class App extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
this.innerHTML = this.template;
}
get template() {
return `
<div>This is a div</div>
`;
}
}
// What is the difference between these two methods?
window.customElements.define('vs-app', App);
document.registerElement('vs-app', App);
Run Code Online (Sandbox Code Playgroud) 如果通过Go中的通道发送大型结构,它是否真的在goroutines之间复制?
例如,在下面的代码中,Go实际上会复制goroutines生产者和消费者之间的所有largeStruct数据吗?
package main
import (
"fmt"
"sync"
)
type largeStruct struct {
buf [10000]int
}
func main() {
ch := make(chan largeStruct)
wg := &sync.WaitGroup{}
wg.Add(2)
go consumer(wg, ch)
go producer(wg, ch)
wg.Wait()
}
func producer(wg *sync.WaitGroup, output chan<- largeStruct) {
defer wg.Done()
for i := 0; i < 5; i++ {
fmt.Printf("producer: %d\n", i)
output <- largeStruct{}
}
close(output)
}
func consumer(wg *sync.WaitGroup, input <-chan largeStruct) {
defer wg.Done()
i := 0
LOOP:
for {
select {
case …Run Code Online (Sandbox Code Playgroud) 我应该如何替换Javascript键中的键字符串:值哈希映射(作为对象)?
这是我到目前为止:
var hashmap = {"aaa":"foo", "bbb":"bar"};
console.log("before:");
console.log(hashmap);
Object.keys(hashmap).forEach(function(key){
key = key + "xxx";
console.log("changing:");
console.log(key);
});
console.log("after:");
console.log(hashmap);
Run Code Online (Sandbox Code Playgroud)
看到它在这个jsbin中运行.
"之前"和"之后"的哈希映射是相同的,因此forEach似乎在不同的范围内.我该如何解决?也许有更好的方法来做到这一点?
jQuery和JavaScript相当新鲜,所以请温柔......
我正在开发一个POC来创建一个"列映射"页面,用户可以将"列标题"列表拖放到新列标题的网格中.我需要构建一个可以发送回SQL数据库的数组.我有这个部分(大部分)按照我的意愿运作.
当项目从左侧的列列表拖动到右侧的标题网格时,如果该项目存在,则代码应更新/替换该索引处的数组项目.如果该项不存在,则应将该项添加到数组中.
例如:如果将"First Name"拖动到"Headers",则应将其添加到索引位置0.如果然后将"First Name"拖动到"with",则应删除索引0处的"First Name"值并添加位置1的值.如果然后将"Last Name"拖动到"with",它应该使用"Last Name"值更新位置1的数组.
$(document).ready(() => {
$(function() {
$('.item').draggable({
cursor: "crosshair",
cursorAt: {
left: 5
},
distance: 10,
opacity: 0.75,
revert: true,
snap: ".target",
containment: "window"
});
});
$(function() {
var array = [];
var arraytext = '';
$('.target').droppable({
accept: ".item",
tolerance: 'pointer',
activeClass: 'active',
hoverClass: 'highlight',
drop: function(event, ui) {
var dropped = $(this);
var dragged = $(ui.draggable);
$(function(index, item) {
var test = '';
array.push($(dragged).text());
arraytext = JSON.stringify(array);
test += "Index Value …Run Code Online (Sandbox Code Playgroud)我有一个带有延迟加载模块的 Angular 4.3.6 应用程序。这是一个部分根路由器:
const routes: Routes = [
{ path: '', redirectTo: 'fleet', pathMatch: 'full' },
{
path: '',
component: AppComponent,
canActivate: [AuthenticationGuard],
children: [
{
path: 'fleet',
loadChildren: "./modules/fleet.module",
canActivate: [AuthenticationGuard]
},
{
path: 'password/set',
loadChildren: "./modules/chooseNewPassword.module",
canActivate: [ChoosePasswordGuard]
}
]
}
]
// Exports RouterModule.forRoot(routes, { enableTracing: true });
Run Code Online (Sandbox Code Playgroud)
这两个示例模块中的我的子路由器:
舰队:
RouterModule.forChild([
{
path: '',
component: FleetComponent,
canActivate: [AuthenticationGuard]
}
]);
Run Code Online (Sandbox Code Playgroud)
选择新密码:
RouterModule.forChild([
{
path: '',
component: ChooseNewPasswordComponent,
canActivate: [ChoosePasswordGuard]
}
]);
Run Code Online (Sandbox Code Playgroud)
该AuthenticationGuard调用一个方法,看起来像这样:
return this.getUserSession().map((userSession: …Run Code Online (Sandbox Code Playgroud) 我已经将代码编写为半工作但是当它执行时它会创建一个无限循环.
我尝试比较用户输入的数据类型.我无法在概念上绕过它,所以我正在比较数字.
HTML:
let button = document.getElementById("button")
var input = document.getElementById("number_of_souls").getElementById("takeinput").value
let user_number = function() {
for (let i = 1; i < 1; i++) {
if (9000 <= input) {
alert("Not many souls")
} else 9000.1 >= input
alert["That's over 9,000!"]
}
}
button.addEventListener("click", user_number)Run Code Online (Sandbox Code Playgroud)
<div>
<h1> How many Souls have you aquired? </h1>
<form id="number_of_souls">
<input id="takeinput"> Souls
<button id="button">submit</button>
</form>
</div>Run Code Online (Sandbox Code Playgroud)
这是Darksouls中的粉丝页面项目.提出的问题是"你获得了多少灵魂?一旦用户提交了一个数字,它应该取数字并返回"不是很多灵魂"或"那超过9,000"的警报.
javascript ×5
angular ×2
ecmascript-6 ×2
channel ×1
components ×1
css ×1
git ×1
git-pull ×1
go ×1
goroutine ×1
html ×1
jquery ×1
json ×1
lazy-loading ×1
node.js ×1
structure ×1
typescript ×1