如何为ternary运算符分配多个值?那不可能吗?我试过这样,但得到错误:
size === 3 ? ( var val1=999, var val2=100; ) : 0;
Run Code Online (Sandbox Code Playgroud)
和
size === 3 ? ( var val1=999; var val2=100; ) : 0;
Run Code Online (Sandbox Code Playgroud)
以上两种方法都会引发错误。如何设置两者var val1和var val2;
我可以直接申报。但我想知道这里的三元运算符方法。
我有一个有子a元素的父母 .当用户mouse over我将子边框颜色更改为红色时.有用.
我的问题是,孩子的长度不是静态的.它是动态的.我加入左边框radius既first和last,但如何添加right-radius到second和last?(因为我不知道孩子的数量)
.parent {
border:5px solid red;
display:inline-block;
position: relative;
border-radius:5px;
box-sizing:border-box;
margin-bottom:3em;
}
.parent a {
display:block;
padding:1em;
border-bottom:1px solid #ddd;
position: relative;
width:50%;
float:left;
box-sizing:border-box;
}
.parent a:nth-child(odd):hover{
border:5px solid #ddd;
margin: -5px;
}
.parent a:nth-child(even):hover{
border:5px solid #ddd;
margin: -5px;
left:10px;
}
.parent a:first-of-type{
border-top-left-radius:5px;
}
.parent a:last-of-type{
border-bottom-left-radius:5px;
}Run Code Online (Sandbox Code Playgroud)
<div class="parent">
<a href="#">1</a><a href="#">2</a><a href="#">3</a><a href="#">4</a><a href="#">5</a>
</div> …Run Code Online (Sandbox Code Playgroud)在我的应用程序中,我有这样的配置:
module.exports = {
'port': process.env.PORT || 8080,
'database': 'mongodb://xxx:xxxx@ds013456.mlab.com:13456/practical',
'secret': 'ilovescotchscotchyscotchscotch'
};
Run Code Online (Sandbox Code Playgroud)
但目前,我想用不同的PORT号码8081或其他方式运行我的应用程序.因为我需要运行2个不同的应用程序,配置方式相同.
什么是正确的方法? - 任何人帮助我?
提前致谢.
我已经尝试了这个答案:如何在node.js中更改process.env.PORT的值?
但我收到此错误:(我使用的是Windows shell)
C:\Tutorials\try\NodePractical\MEAN-Family> env:PORT = 1234 server.js
env:PORT : The term 'env:PORT' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ env:PORT = 1234 server.js
+ ~~~~~~~~ …Run Code Online (Sandbox Code Playgroud) 我正在尝试使3d元素保持flex容器的全宽。但没有得到重用。有人建议我正确的方式ie11吗?
.parent{
border:1px solid red;
display:flex;
justify-content:space-between;
padding:0 40px;
}
.child{
flex:0 0 30%;
border:1px dashed green;
}
.child.last{
/* not working */
width:100%;
}Run Code Online (Sandbox Code Playgroud)
<div class="parent">
<div class="child">one</div>
<div class="child">two</div>
<div class="child last">three</div>
</div>Run Code Online (Sandbox Code Playgroud)
我试图像这样从我的本地主机获取数据:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class SearchServiceService {
apiRoot:string = 'https://itunes.apple.com/search';
results:Object[];
loading:boolean;
constructor(private http:HttpClient) {
this.results = [];
this.loading = false;
}
search(term:string){
let promise = new Promise((resolve, reject) => {
let apiURL = `${this.apiRoot}?term=${term}&media=music&limit=20`;
this.http.get(apiURL).toPromise().then(res => {
// console.log( res.json() );
resolve();
}, function(error){
console.log('error is', error);
})
});
return promise;
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Chrome浏览器。为了防止出现此CORS问题,我使用此扩展名:
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi/related?hl=en-US
但是仍然出现错误为:
Failed to load https://itunes.apple.com/search?term=Moo&media=music&limit=20: …Run Code Online (Sandbox Code Playgroud) 我正在为我的项目做面包屑。我这里有两个问题:
两者该如何解决呢?
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute, RoutesRecognized, NavigationStart, NavigationEnd, Params, PRIMARY_OUTLET } from '@angular/router';
import { filter, map } from 'rxjs/operators';
import { BreadCrumbsService } from './../../services/bread-crumbs.service';
@Component({
selector: 'bread-crumbs',
templateUrl: './bread-crumbs.component.html',
styleUrls: ['./bread-crumbs.component.scss']
})
export class BreadCrumbsComponent implements OnInit {
breadcrumbList: Array<any> = [];
/**
* Setting Breadcrumb object, where name for display, path for url match,
link for heref value, getting datas from BreadCrumbsService service
*/
constructor(private router: Router, …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,有条件地我正在添加一个类.当用户输入的东西我正在检查值,因此我添加了类名.它工作正常.
但它只更新一组(keyup)='0'- 设置一些值keyup.这不像angular 1这里.
所以任何人都解释我为什么要设置(keyup)=0这里?它为我们做了什么?
这是我的代码:
import {Component} from "angular2/core"
@Component({
selector : 'my-component',
template : `
<h2>My Name is: {{name}}
<span [class.is-awesome]="formReplay.value === 'yes' ">So good</span>
</h2>
<input type="text" #formReplay (keyup)="0" />
`,
styles : [`
.is-awesome{
color:green;
}
`]
})
export class MyComponent {
name = "My Name";
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试ngIf使用async管道来实现。但不起作用。有人帮我吗?
这是我的 html:
<div class="response-container">
xx {{response | async | json }}
<div class="failed-error" *ngIf="(response.responseFail | async )">
{{response.message}}
</div>
<div class="success-msg" *ngIf="(response.responseSucc | async) === 'true' ">
{{response.message}}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
在上面xx {{response | async | json }}它打印为:
xx { "responseFail": false, "responseSucc": true, "message": "success" }
但是为什么这不适用于*ngIf条件?
这是我的 ts 文件:
this.store.pipe(select(subscribe.getRegCategories)).pipe(takeUntil(this.ngUnsubscribe)).subscribe(data => {
if (data && data.length) {
this.allRegCategories = data;
}
});
Run Code Online (Sandbox Code Playgroud)
当我去测试时出现错误:
this.store.pipe(select(subscribe.getRegCategories)).pipe(takeUntil(this.ngUnsubscribe)).subscribe(data => {
TypeError: Cannot read property 'pipe' of undefined
Run Code Online (Sandbox Code Playgroud)
这里如何提供管道?解决这个问题的正确方法是什么?
这是我的测试规范文件:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Store, select } from '@ngrx/store';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientModule } from '@angular/common/http';
import { ShellViewProgMgmtComponent } from './shell-view-prog-mgmt.component';
import { ViewProgMgmtComponent } from './../../components/view-prog-mgmt/view-prog-mgmt.component';
import * as actions from './../../state/actions/setup-config.actions';
describe('ShellViewProgMgmtComponent', () => {
let component: …Run Code Online (Sandbox Code Playgroud) 我正在开发示例应用程序来学习angularjs使用node.js. 当我将数据发布到后端以创建新数据时,family我收到错误:
Error: $http:badreq
Bad Request Configuration
Http request configuration url must be a string. Received:
{
"method":"POST",
"url":"api/family",
"data": {
"username":"fagruddin",
"password":"valaanur",
"familyLeader":"fagruddin",
"husband":"fagruddin",
"wife":"rejiya",
"child":2
},
"headers":{
"Content-Type":"application/x-www-form-urlencoded"
}
}
Run Code Online (Sandbox Code Playgroud)
这里出了什么问题?有人帮我解决这个问题吗?
angular ×5
angular8 ×3
css ×2
css3 ×2
html ×2
angular-http ×1
angular6 ×1
angularjs ×1
express ×1
flexbox ×1
javascript ×1
ngrx ×1
node.js ×1
typescript ×1