在一个按钮点击我有功能,
inviewMockupEvent(data) {
console.log(data);
this.router.navigate(['/page-mockup'], { queryParams: { data: data }, skipLocationChange: true });
}
console.log(data) give the result as {mockup_id: "123", project_id: "456", module_id: "678", release_id: "890", requirement_id: "432", …}
Run Code Online (Sandbox Code Playgroud)
在导航组件中,我获取的数据如下,
ngOnInit() {
this.activatedRoute.queryParams.subscribe(params => {
let data = params['data'];
console.log(data);
console.log(JSON.stringify(data));
});
Run Code Online (Sandbox Code Playgroud)
在哪里,
console.log(data) gives output as [object Object]
console.log(JSON.stringify(data)) gives output as "[object Object]"
Run Code Online (Sandbox Code Playgroud)
并且,
console.log(data.mockup_id) gives result undefined
Run Code Online (Sandbox Code Playgroud)
在这里我需要检索对象值,但无法获取它。请帮助我通过查询参数检索数据并使用打字稿ngOnit而不使用 html获取数据。
javascript typescript angular-routing angular angular4-router
我正在使用ng2圆环图来显示一些项目,根据圆环图文档,它的工作正常,但我需要更改的是,每个切片的标签显示仅在悬停但我需要的是它应该是默认情况下,每个切片.
Dashboard.component.html:
<canvas #mycanvas baseChart
[data]="doughnutChartData"
[labels]="doughnutChartLabels"
[chartType]="doughnutChartType"
[colors]="colors"
[options]="options"
(chartHover)="chartHovered($event)"
(chartClick)="chartClicked($event)">
</canvas>
Run Code Online (Sandbox Code Playgroud)
Dashboard.component.ts:
public doughnutChartLabels:string[] = ['Running', 'Stop', 'Idle'];
public doughnutChartData:number[] = [1, 4, 5];
public doughnutChartType:string = 'doughnut';
public colors: any[] = [{ backgroundColor: ["#008000", "#FF0000", "#FFA500"] }];
Run Code Online (Sandbox Code Playgroud)
我需要的东西与图像完全一样,
标签应该在每个切片中都是默认的,只需要使用纯打字稿而不是javascript即可实现.请帮助我达到预期的效果.
我正在使用 angular 6,但无法在选择框中将所选选项显示为默认值,
HTML包括,
<select class="form-control selectBox" name="username" #username="ngModel" required ngModel>
<option disabled selected>Select User Name</option>
<option *ngFor="let user of userList" [value]="user.uid">{{user.name }}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
:
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
userList: any = [
{
"name" : "Test User"
},
{
"name" : "Hello World"
},
{
"name" : "User Three"
}
]
}
Run Code Online (Sandbox Code Playgroud)
它在选择框中默认显示空值。
如何在行中的选择框中将所选选项显示为默认值?
<option disabled selected>Select User Name</option> …Run Code Online (Sandbox Code Playgroud) 我正在制作角度应用程序,并且我有一个空数组,例如,
users: any = [];
Run Code Online (Sandbox Code Playgroud)
然后我进行服务调用以ngOnInit将数据存储到users数组中,例如,
ngOnInit() {
//Getting the data from json
this.httpClient.get('https://api.myjson.com/bins/n5p2m').subscribe((response: any) => {
console.log("response", response.data);
response.data.forEach(element => {
//Pusing the data to users array
this.users.push(element);
});
})
//Trying to get the complete array after push of the element from the service response data
console.log("users array", this.users);
//But it shows empty array
}
Run Code Online (Sandbox Code Playgroud)
但我无法获取数据,console.log("users array", this.users);因为服务呼叫造成了延迟。
如何将数据推送到this.users服务中,当我们在服务外部调用时,它应该具有填充的数据,而不是像现在这样为空。
还做了一个关于它的工作 stackblitz https://stackblitz.com/edit/angular-q3yphw
请查看具有当前结果的控制台。
当前结果是console.log("users array", this.users);空数组[] …
我正在使用jquery和jquery ui进行我添加的角度项目中的拖放功能,
Index.html:
<link href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
Run Code Online (Sandbox Code Playgroud)
Component.ts:
declare var jquery:any;
declare var $ :any;
export class DropAreaComponent implements OnInit, OnDestroy {
ngOnInit(): void {
$("#people").sortable({
update: function(e, ui) {
$("#people .draggable").each(function(i, element) {
$(element).attr("id", $(element).index("#people .draggable"));
$(element).text($(element).text().split("Index")[0] + " " + "Index: " + " => " + $(element).attr("id"));
});
}
});
}
Run Code Online (Sandbox Code Playgroud)
Component.html:
<ul id="people">
<li *ngFor="let person of people; let i = index">
<div class="draggable" id={{i}}>
<p> <b> {{ person.name }} </b> Index …Run Code Online (Sandbox Code Playgroud) 我正在使用 vee-validate 来验证注册表,并且我已经编写了如下代码,
<form @submit.prevent="signUp()">
<div class="form-group" :class="{'has-error': errors.has('register.mobile_number') }" >
<input v-model="register.mobile_number" v-validate="register.mobile_number" data-vv-rules="required" required class="form-control" type="number" placeholder="Mobile Number">
</div>
<div class="form-group" :class="{'has-error': errors.has('register.email') }" >
<input v-model="register.email" v-validate="register.email" class="form-control" type="email" data-vv-rules="required|email" placeholder="Email">
</div>
<div class="form-group" :class="{'has-error': errors.has('register.password') }" >
<input v-model="register.password" v-validate="register.password" name="password" data-vv-rules="required" class="form-control" type="password" placeholder="Password">
</div>
<div class="form-group" :class="{'has-error': errors.has('register.confirm_password') }" >
<input v-model="register.confirm_password" v-validate="register.confirm_password" name="confirm_password" data-vv-as="password" data-vv-rules="required|confirmed:password" class="form-control" type="password" placeholder="Confirm Password">
</div>
<div class="modal-footer btn-center">
<button type="submit" class="btn btn-default">Sign Up</button>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
脚本是:
export default …Run Code Online (Sandbox Code Playgroud) 我有一行有两列,如下面的代码片段所示。在第 1 列中,标签下有7 个列表项ul。
但我需要在第 1 列中仅显示 5 个列表项,其余项目应移至下一列..(即移至第 2 列)。
如果列表项超过计数 (5),我怎样才能实现根据计数(此处为 5)自动将列表项移动到下一列的结果。
结果预计仅在 html 和 css 中,并且不应该有任何像 jquery 或任何其他第三方的库。
当前片段:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-xs-4 mr-4">
<ul class="list-group">
<li class="list-group-item">List Item 1</li>
<li class="list-group-item">List Item 2</li>
<li class="list-group-item">List Item 3</li>
<li class="list-group-item">List Item 4</li>
<li class="list-group-item">List Item 5</li>
<li class="list-group-item">List Item 6</li>
<li class="list-group-item">List Item 7</li>
</ul>
</div>
<div class="col-xs-4 mr-4">
Column-2
</div>
</div> …Run Code Online (Sandbox Code Playgroud)在我的角度应用程序中,我正在制作一个复选框并捕获复选框更改事件并将选中的值推入数组中。
在这里,如果我们取消选中该复选框,则 obj 也会被推送到数组中。
如果取消选中如何从数组中删除obj。
网页:
<div *ngFor="let item of order; let i = index">
<input type="checkbox" [id]="item+i" [name]="item"[(ngModel)]="item.Checked" (change)="getCheckboxValues(item)">
<label [for]="item+i"> {{item}} </label>
</div>
Run Code Online (Sandbox Code Playgroud)
时间:
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
order = ['One','Two','Three','Four'];
newArray : any = [];
//Checkbox Change detecting function
getCheckboxValues(data) {
let obj = {
"order" : data
}
// Pushing the object …Run Code Online (Sandbox Code Playgroud) 我正在使用角度6应用程序,我正在使用图像上传选项,其中,
HTML:
<img [src]="url ? url : 'https://www.w3schools.com/howto/img_avatar.png'"> <br/>
<input type='file' (change)="onSelectFile($event)">
Run Code Online (Sandbox Code Playgroud)
TS:
onSelectFile(event) {
if (event.target.files && event.target.files[0]) {
var reader = new FileReader();
reader.readAsDataURL(event.target.files[0]); // read file as data url
reader.onload = (event) => { // called once readAsDataURL is completed
this.url = event.target.result;
}
}
}
Run Code Online (Sandbox Code Playgroud)
使用stackblitz: https ://stackblitz.com/edit/angular-file-upload-preview-ekyhgh
在这里我给出的东西html input file显示选择文件作为文本,但我需要点击配置文件图像,该文件夹需要从本地显示(这将出现在正常点击选择文件按钮)..
为了混淆我有一个我需要的链接是https://codepen.io/anon/pen/PXjaJv
在这里你可以看到悬停在图像上的文本显示为Drag your photo here or browse your computer..(相同的文字出现在给定的链接默认,因为那里没有图片,但我只需要悬停,因为我已经有头像图像已经如此悬停在任何图像上我需要显示更改个人资料图片的文本)
忽略此链接中的图像裁剪和丢弃https://codepen.io/anon/pen/PXjaJv,但我唯一需要的是UI更改,例如悬停时制作叠加文本,然后单击文本从计算机浏览图片更改然后使用删除选项更改配置文件图片,该选项将返回到头像图像本身(如果已删除)..
请帮助我使用纯粹的角度/打字稿方式而不是jquery来实现结果.
网页:
选择框:1
<select v-model="facilitySelected" name="facilities" multiple="multiple" id="facilities" size="4" class="form-control">
<option v-for="availability in availableFacilities" v-bind:value="availability">{{availability.label}}--</option>
</select>
Run Code Online (Sandbox Code Playgroud)
点击事件:
<a @click="removeFacilities" class="btn btn-default remove_option" rel="facilities2" id="remove"><i class="fa fa-arrow-left"></i></a>
<a @click="addFacilities" class="btn btn-default add_option" rel="facilities2" id="add"><i class="fa fa-arrow-right"></i></a>
Run Code Online (Sandbox Code Playgroud)
选择框:2
<select name="facilities" multiple="multiple" id="facilities2" size="4" class="form-control">
<option v-for="facility in selectedFacilities" v-bind:value="facility.value">{{facility.label}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
剧本是,
export default {
data(){
return{
facilitySelected:[],
availableFacilities: [{
value: 1,
label: 'Double (Non a/c)'
},
{
value: 2,
label: 'Premium Double (a/c)'
},
{
value: 3,
label: 'Standard Double (a/c)'
}
], …Run Code Online (Sandbox Code Playgroud) javascript ×8
angular ×7
typescript ×7
angular6 ×2
arrays ×2
css ×2
html ×2
vue.js ×2
vuejs2 ×2
bootstrap-4 ×1
chart.js ×1
checkbox ×1
jquery ×1
jquery-ui ×1
ng2-charts ×1
validation ×1