我有一个名为"Node"的组件,它应该显示一个帖子,但我有一个以上的帖子类型,每个类型都有自己的视图(布局).
所以这个组件有一个ID参数,用于从服务获得post响应,然后根据post类型显示正确的布局.
例如:localhost/test_app/node/123123是id参数.
@Component({
selector: 'node',
directives: [Post, Project],
template: `
<post *ngIf="response.post.post_type == 'post'" content="response.post"></post>
<project *ngIf="response.post.post_type == 'project'" content="response.post"></project>
`,
})
export class Node{
id: number;
response: any;
constructor(private _param: RouteParams,
public service: Service
){
this.id = +_param.get('id');
}
ngOnInit(){
this.service.get(this.id).subscribe(
res=> this.response = res.json()
);
}
}
Run Code Online (Sandbox Code Playgroud)
@Component({
selector: 'node',
directives: [Post, Project],
template: '<div #container></div>'
})
export class Node{
id: number;
response: any;
constructor(private _param: RouteParams,
public service: Service,
private loader:DynamicComponentLoader,
private …Run Code Online (Sandbox Code Playgroud) 我在Angular 2应用程序中使用ngx-progressbar bar.当应用程序首先加载它工作正常.第二次出现错误.我引用了一些像medium.com这样的文章来订阅对象.我没弄清楚.每次点击路由器链接时我都需要进度栏.
进度条形码:
import { Component, AfterContentInit} from '@angular/core';
import { NgProgress } from 'ngx-progressbar'
@Component({
selector: 'link-outlet',
template: '<ng-progress [showSpinner]="false"></ng-progress>'
})
export class RoutingDirectiveComponent implements AfterContentInit{
constructor(private ngProgress: NgProgress) {
}
ngAfterContentInit(){
this.ngProgress.start();
setTimeout(()=>{
this.ngProgress.done();
}, 2000);
}
}
Run Code Online (Sandbox Code Playgroud)
您的建议将不胜感激.
我正在使用javascript开发8个益智游戏,我通过改组拼图瓷砖阵列来洗牌
var shuffleArray = (array) => {
var currentIndex = array.length, temporaryValue, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
};
Run Code Online (Sandbox Code Playgroud)
我想给用户提供选择难度的选项:简单,中等,难度,我该如何实现这个?
我会解释一下我的建议.(这是打字稿)
拼图数组是一个类的数组 PuzzleNode
export class PuzzleNode {
goal: Node;
current: Node;
}
Run Code Online (Sandbox Code Playgroud)
当我洗牌时,我不会碰到puzzleArray,但我会current像这样洗牌
shuffle() {
this.shuffledNodes = shuffleArray(this.shuffledNodes);
for (let i = 0; i < this.shuffledNodes.length; i++) {
this.puzzleNodes[i].current = this.shuffledNodes[i];
}
/** Keep shuffling until getting …Run Code Online (Sandbox Code Playgroud) 
我有服务器客户端应用程序,它是一个文件管理器,
我的问题是当我进入需要访问控制(如系统文件夹)的文件夹时,它变为只读,但我需要移动/删除或创建新文件夹,我该如何获得许可这样做吗?
这是我在服务器端创建新文件夹的方法
public void NewFolder(string path)
{
try
{
string name = @"\New Folder";
string current = name;
int i = 0;
while (Directory.Exists(path + current))
{
i++;
current = String.Format("{0} {1}", name, i);
}
Directory.CreateDirectory(path + current);
Explore(path); //this line is to refresh the items in the client side after creating the new folder
}
catch (Exception e)
{
sendInfo(e.Message, "error");
}
}
Run Code Online (Sandbox Code Playgroud) 我需要修剪给定的IP地址以获得它的前3个部分
例:
"192.168.1.20"➨"192.168.1."
"29.6.60.241"➨"29.6.60."
在每次从WCF服务调用函数时,在客户端,它等待直到WCF服务上的函数完成,就像调用本地函数一样.所以我为每个在新线程中启动预期函数的函数添加了一个额外的函数,所以我的几乎所有函数都是这样的:
EX:
我从CLIENT方面调用一个函数client.ReceiveFile():
private void SendFile(Socket socket, Job job, DoWorkEventArgs e)
{
UpdateInfo(job.Name, job.Icon, job.Size);
client.ReceiveFile((_File)job.Argument, bufferSize);
SizeAll = job.Size;
UpdateCurrFile(((_File)job.Argument).Path, "1");
SendX(socket, ((_File)job.Argument).Path, e);
}
Run Code Online (Sandbox Code Playgroud)
在服务器中我必须这样做:
public void ReceiveFile(_File file, int bufferSize)
{
System.Threading.Thread th = new System.Threading.Thread(unused => ReceiveFileTh(client, file.Name, file.Size, bufferSize));
th.Start();
}
private void ReceiveFileTh(Socket client, string destPath, long size, int bufferSize)
{
try
{
ReceiveX(client, destPath, size, bufferSize);
}
finally
{
CloseClient();
}
}
Run Code Online (Sandbox Code Playgroud)
关键是,当我从客户端sendFile时,它告诉服务开始接收,但如果我没有启动新线程,客户端将等待服务接收文件,并且不会发送文件数据.
因此,WCF支持一种不会使客户端等待服务功能完成的方式!或者我将不得不使用上述方法?
我正在尝试让浏览器同步在我的项目中工作,而不是使用live-server
应用程序结构如下所示:
personal-app
??? node_modules
??? src
??? app
? ??? app.ts
??? index.html
Run Code Online (Sandbox Code Playgroud)
在index.html中,脚本从node_modules dir 加载
<script src="../node_modules/systemjs/dist/system.src.js"></script>
<script src="../node_modules/angular2/bundles/angular2.dev.js"></script>
Run Code Online (Sandbox Code Playgroud)
当我使用live-server时,它会加载脚本并且工作正常,但是由于我移动到浏览器同步,脚本不会加载.这是gulpfile.js中的代码:
gulp.task('serve', function() {
browserSync.init({
server: {
baseDir: "./src"
}
});
gulp.watch(sassfiles, ['sass']);
gulp.watch(htmlfiles).on('change', browserSync.reload);
});
Run Code Online (Sandbox Code Playgroud)
当我将src路径作为基础目录时,baseDir: "./src"
该站点可以工作,但脚本不会加载
但当我改变它 baseDir: "./"
该网站给了我不能GET /,但是当我将"/ src"添加到chrome中的url时,如" http:// localhost:3000/src ",它可以工作.
所以这里的问题是浏览器同步不会从其baseDir的父文件夹加载脚本.
我需要一种方法来配置浏览器同步以从其启动baseDir : "./"但从子文件夹加载主页index.html.
浏览器同步可能吗?
我有一个数组数组,我想从paths数组中获取最小(最短)路径
paths = [
["LEFT", "RIGHT", "RIGHT", "BOTTOM", "TOP"],
["RIGHT", "LEFT", "TOP"],
["TOP", "LEFT"]
];
paths.map((path)=> Math.min(path.length));
Run Code Online (Sandbox Code Playgroud) 为什么要在 Angular 中的内置指令ngTemplateOutlet和ngComponentOutlet 上使用cdkPortal。它们不是都提供相同的功能吗?CDK 门户中是否有没有内置指令的特定功能?
我一直在阅读有关如何检查 LAN 上特定端口上的所有侦听服务器的信息,最后我编写了一些代码,它可以按我想要的方式工作。
我正在使用 System.Threading.Tasks.Parallel 尽快连接到所有 254 个 IP 地址,例如
:192.168.1。1 - 192.168.1。第254章
我需要的是为这些连接尝试设置超时,因为失败时需要大约 15-20 秒才能打印:“连接失败”..那么我该怎么做?
这是客户端代码:
static void Main(string[] args)
{
Console.WriteLine("Connecting to IP addresses has started. \n");
Parallel.For(1, 255, i =>
{
Connect("192.168.1." + i);
});
Console.ReadLine();
}
private static void Connect(string ipAdd)
{
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
SocketAsyncEventArgs e = new SocketAsyncEventArgs();
IPEndPoint ipEnd = new IPEndPoint(IPAddress.Parse(ipAdd), 9990);
e.RemoteEndPoint = ipEnd;
e.UserToken = s;
e.Completed += new EventHandler<SocketAsyncEventArgs>(e_Completed);
Console.WriteLine("Trying to connect …Run Code Online (Sandbox Code Playgroud) c# ×4
angular ×3
javascript ×2
angular-cdk ×1
arrays ×1
asynchronous ×1
browser-sync ×1
components ×1
ecmascript-6 ×1
gulp ×1
permissions ×1
sockets ×1
string ×1
trim ×1
typescript ×1
wcf ×1