例如,我在路上/cars?type=coupe,我想用其他查询参数导航到同一个端点(但保留现有的查询参数).我正在尝试这样的事情
<a [routerLink]="['/cars']" [queryParams]="{model: 'renault'}" preserveQueryParams>Click</a>
Run Code Online (Sandbox Code Playgroud)
保留初始查询参数(type = cars)但忽略添加的(model = renault).这是预期/正确的行为还是某种错误?看起来preserveQueryParams优先于queryParams?还有其他顺利解决方案吗?
我正在尝试从rc1迁移到rc4,我无法获取查询字符串参数.ActivatedRoute对象始终为空.
hero.component.ts
import {Component, OnInit} from "@angular/core";
import {Control} from "@angular/common";
import {ROUTER_DIRECTIVES, ActivatedRoute} from '@angular/router';
@Component({
template: '../partials/main.html',
directives: [ROUTER_DIRECTIVES]
})
export class HeroComponent implements OnInit {
constructor(private _activatedRoute: activatedRoute) {
}
ngOnInit() {
this._activatedRoute.params.subscribe(params => {
console.log(params);
});
}
}
Run Code Online (Sandbox Code Playgroud)
main.ts
import {bootstrap} from '@angular/platform-browser-dynamic';
import {HTTP_PROVIDERS, RequestOptions, Http} from '@angular/http';
import {AppRouterProviders} from './app.routes';
bootstrap(AppComponent, [
AppRouterProviders,
HTTP_PROVIDERS
]);
Run Code Online (Sandbox Code Playgroud)
app.component.ts
import {Component, OnInit} from '@angular/core';
import {HeroComponent} from './hero.component';
import {RouteConfig, Router, ROUTER_DIRECTIVES} from '@angular/router';
@Component({
selector: …Run Code Online (Sandbox Code Playgroud) 尝试访问不允许的页面时,我尝试将用户导航到错误页面.问题是skipLocationChange在这种情况下不起作用.它导航到错误页面,但URL更改为根.如何保持原始网址用户?
resolve(route: ActivatedRouteSnapshot): Observable<any|boolean>|boolean {
return this.apiclientService.get('cars/' + route.params['id']).map(
response => {
if (response.data.user_id === this.authService.user().id) {
return response.data;
}
this.router.navigate(['/404'], { skipLocationChange: true });
return false;
}
).catch(error => {
this.router.navigate(['/404'], { skipLocationChange: true });
return Observable.of(false);
});
}
Run Code Online (Sandbox Code Playgroud) 我有一个数据库中的项目列表,每个项目都可以选择向下或向上投票.这些投票与其他项目字段一起存储在MySql中.例如,像这样:
Schema::create('items', function ($table) {
$table->increments('id');
$table->text('message');
$table->integer('up_votes')->unsigned()->default(0);
$table->integer('down_votes')->unsigned()->default(0);
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
用户可以每天投票/投票.当用户决定投票时,我将他的决定存储到memcached一天,并相应地增加其中一个字段(up_votes或down_votes).
$voteKey = sprintf('%s-%s', $request->ip(), $item->id);
if (!Cache::has($voteKey)) {
$vote = $request->get('vote');
$this->item->increment($vote ? 'up_votes' : 'down_votes');
Cache::put($voteKey, $vote, (60*24));
}
Run Code Online (Sandbox Code Playgroud)
接下来我想了解某些用户如何投票的信息.我在模型中创建了访问器:
public function getVoteAttribute($value)
{
$voteKey = sprintf('%s-%s', Request::ip(), $this->id);
return $this->attributes['vote'] = Cache::get($voteKey);
}
protected $appends = ['vote'];
Run Code Online (Sandbox Code Playgroud)
这样做是否明智?或者长列表会出现性能问题?如果返回100个项目,则每个用户有100个与memcached的连接.我怎样才能改进这一点,或者这是我不应该担心的事情,因为缓存服务器可以毫无问题地处理这么多连接.
我想建立一个在线考试,这个考试有5页,每个页面有一个倒计时器(120秒)和4个问题.120秒后,用户将自动转移到下一页,或者可以在此之前单击下一个按钮.
Laravel5.4和VueJs,用户回答的每个问题都有一个Ajax请求.我想要的是阻止用户看到其他页面.每页必须最多可见120秒.用户不应该单击后退按钮并查看以前的页面.这有可能吗?
我要创建这个应用程式Vuejs和vue-router,但我不知道如何与实现这个vue-router,我做了一些研究,但有没有太多的结果!
或者也许我不应该使用vue-router,并使用我自己的简单路由器,例如:
$("#page1").show();
$("#page2").hide();
$("#page3").hide();
.
.
// after 120 secs
$("#page1").hide();
$("#page2").show();
$("#page3").hide();
.
.
// i think this is not secure !
Run Code Online (Sandbox Code Playgroud)
任何想法都表示赞赏.谢谢.
更新:
在此考试中,用户可以看到English words从words表中随机选择的列表, 而不是其他内容!用户点击他认为自己知道其含义的每个单词!每次点击都有一个ajax请求,用于保存results表中单词的id .此外,如果用户点击假字超过3次,fake_words则会选择随机选择50个字的表,actual words测试将失败.最终结果将告诉用户他有多少词汇技能.
更新2:我尝试这样做vue-router,但在开始编码之前,我想也许它不应该实现,vue-router因为所有问题在一个查询中随机从DB中获取,然后在考试开始之前,所有这些都发送(ajax)到浏览器,现在该怎么办?将它们分成不同的数组并将每个问题数组发送到我的一个页面?我必须这样做吗?我不能只v-for为他们使用一个?如果我决定更改问题的数量怎么办?然后我想我每次都要触摸我的代码并创建新页面vue-router或删除其中一个页面.
我通过HTML表单以字符串形式接收自定义js和css脚本。然后将此字符串保存在文件系统上的文件中。问题是如何在每次生成/更新文件时将其最小化。我正在用gulp和laravel不老长寿药。我的第一个想法是调用exec(“ gulp something”),但不确定如何配置gulp。
我正在使用laravel宅基地解决方案进行开发,但现在我想迁移到docker.问题是如何"膨胀"应该是我的容器.当我说"臃肿"时,我指的是每个容器应该有多少模块/服务.例如,我创建了四个自定义容器,如下所示:
php
-> php-fpm
-> composer
-> memcached
-> redis
mysql
-> mysql
nginx
->nginx
node
->gulp
->bower
->npm
->grunt
Run Code Online (Sandbox Code Playgroud)
问题是,如果这是正确的聚类或我应该创建单独的容器让我们说为grunt,bower,memcached等?如何决定什么在一起以及分隔容器?有规则吗?应该和生产一样发展吗?
我创建了简单的WebSocket服务和组件,当通过WebSocket接收新数据时,我很难更新视图.
websocket.service.ts
import {Injectable} from "angular2/core";
import {Observable} from 'rxjs/Observable';
@Injectable()
export class WebsocketService {
observable: Observable;
websocket = new WebSocket('ws://angular.local:8080');
constructor() {
this.observable = Observable.create(observer =>
this.websocket.onmessage = (msg) => observer.next(msg);
this.websocket.onopen = (msg) => console.log('openned');
);
}
}
Run Code Online (Sandbox Code Playgroud)
runner.component.ts
import {Component} from "angular2/core";
import {WebsocketService} from "./websocket.service";
@Component({
selector: "runners-list",
templateUrl: "../partials/runners-list.html",
providers: [WebsocketService],
styleUrls: ["../css/app.css"]
})
export class RunnerComponent {
output: any;
constructor(private _websocketService: WebsocketService) {
_websocketService.observable.subscribe(
function onNext(data) {
this.output = data;
console.log(this.output);
},
function onError(error) …Run Code Online (Sandbox Code Playgroud) 我正在提供一些服务,并且我有一个 setup.sh 文件,必须第一次(或更新时)执行该文件。该脚本应该创建某种别名,可以从该终端或新终端访问该别名(也在系统重新启动后)。该别名应指向另一个可执行 sh 文件。
setup.sh 文件:
#!/bin/bash
alias customservice='./customservice.sh "$@"'
Run Code Online (Sandbox Code Playgroud)
如您所见,此 customservice.sh 脚本已准备好接受多个参数。使用这个自定义服务别名,我想像这样调用这个脚本:
customservice //显示帮助
customservice启动
customservice停止
customservice exec bash
...
我的 customservice.sh 文件:
if [ $# -eq 1 ] && [ $1 = "start" ]; then
//do something
elif [ $# -eq 1 ] && [ $1 = "stop" ]; then
//do something
elif [ $# > 1 ] && [ $1 = "exec" ]; then
//do stuff with ${@:2}
else
echo "help"
fi
Run Code Online (Sandbox Code Playgroud)
也许 customscript Kill 命令也不错。它应该完全删除这个别名。 …
我很难用USB在电视上安装.wgt文件.应用程序通常在模拟器上工作.我需要所有证书.我的经销商证书具有公共特权级别,我的模拟器和我的电视(我想测试我的应用程序)的DUID.在我的USB root中,我创建了userwidget文件夹并复制了.wgt文件.当我在电视上插入USB时,它会检测到它,但几秒钟后我收到类似这样的消息:使用USB软件包安装失败.我已经尝试了几乎所有的东西,但我的想法已经用完了可能出错的地方.我假设有证书/权限,但不知道是什么.我的电视型号是UE48J5570.
更新:我还在电视上启用了开发人员模式,并以开发用户身份登录.
angular ×4
javascript ×4
typescript ×3
laravel ×2
alias ×1
android ×1
bash ×1
caching ×1
containers ×1
css ×1
docker ×1
eloquent ×1
gulp ×1
linux ×1
mysql ×1
node.js ×1
observable ×1
php ×1
resolve ×1
shell ×1
tizen ×1
vue-router ×1
vue.js ×1
vuejs2 ×1