在Angular 1中,我可以使用以下选项为下拉框选择默认选项:
<select
data-ng-model="carSelection"
data-ng-options = "x.make for x in cars" data-ng-selected="$first">
</select>
Run Code Online (Sandbox Code Playgroud)
在Angular 2中我有:
<select class="form-control" [(ngModel)]="selectedWorkout" (ngModelChange)="updateWorkout($event)">
<option *ngFor="#workout of workouts">{{workout.name}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
如果我的选项数据是:我如何选择默认选项:
[{name: 'arm'}, {name: 'back'}, {name:'leg'}]而我默认的价值是back?
如果我希望每次加载组件时都会发生函数x,无论是第一次加载,我都会导航到另一个站点并导航回来,或者是组件第五次加载.
我应该把函数x放入什么?组件构造函数还是OnInit?
我如何用python解析json api响应?我目前有这个:
import urllib.request
import json
url = 'https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty'
def response(url):
with urllib.request.urlopen(url) as response:
return response.read()
res = response(url)
print(json.loads(res))
Run Code Online (Sandbox Code Playgroud)
我收到此错误:TypeError:JSON对象必须是str,而不是'bytes'
什么是pythonic方式来处理json apis?
我有一个角度2的下拉选择表格.
目前:当我选择一个选项时,option name会将其传递给我的onChange函数$event
通缉:当我选择一个选项时,我想workout.id进入我的onChange功能.
我怎样才能做到这一点?
<select class="form-control" [ngModel]="selectedWorkout" (ngModelChange)="onChange($event)">
<option *ngFor="#workout of workouts">{{workout.name}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
Controller
onChange(value){
alert(JSON.stringify(value));
}
Run Code Online (Sandbox Code Playgroud) 组件如何更改另一个组件上的变量.例:
我有一个组件 app.component.ts
@Component({
selector: 'my-app',
template: `
<nav *ngIf="onMain == false">
Hello
</nav>
`
})
export class AppComponent{
onMain: Boolean;
constructor(){
this.onMain = false;
}
}
Run Code Online (Sandbox Code Playgroud)
我有另一个组件,我想在我的应用程序组件中更改onMain main.component.ts
import {AppComponent} from '../app.component';
@Component({
selector: 'main-app',
template: ``
})
export class MainComponent{
constructor() {
this.appComponent = AppComponent;
this.appComponent.onMain = true;
}
}
Run Code Online (Sandbox Code Playgroud)
我希望Hello会消失,但事实并非如此.如何让一个组件更改另一个组件的值?
我有一个身份验证服务,使经过身份验证的变量等于true或false.
checkAuthentication(){
this._authService.getAuthentication()
.subscribe(value => this.authenticated = value);
}
Run Code Online (Sandbox Code Playgroud)
如何this.authenticated更改值时如何执行函数?ngOnChanges没有发现变化.
我有一个全局常量,如根目录,我希望每个组件都有权访问.在另一个stackoverflow问题中,答案是创建一个常量类并将其导入到每个组件.
有没有办法引导常量类,以便应用程序中的每个组件都可以访问它而无需任何其他导入?
到目前为止,我有这个,但它不起作用,如何提升常量类,然后在我的组件中访问?
constants.ts
export class Constants{
root_dir: string;
constructor(){
this.root_dir = 'http://google.com/'
}
}
Run Code Online (Sandbox Code Playgroud)
main.ts
import {bootstrap} from 'angular2/platform/browser'
import {Constants} from './constants'
bootstrap([
provide(Constants, {useClass: Constants})
]);
Run Code Online (Sandbox Code Playgroud)
random.component.ts
import {Component, bind} from 'angular2/core';
import {Injector} from 'angular2/core';
@Component({
selector: 'my-app',
template: `{{test}}`
})
export class RandomComponent{
test: string;
constructor(){
this.test = injector.get(Constants.root_dir);
}
}
Run Code Online (Sandbox Code Playgroud) @types是否使用与无类型包相同的版本控制?
npm i bluebird @types/bluebird -S 给我
"@types/bluebird": "^3.5.0",
"bluebird": "^3.5.0",
Run Code Online (Sandbox Code Playgroud)
似乎很合理.
npm i request @types/request -S 给我
"@types/request": "0.0.41",
"request": "^2.81.0",
Run Code Online (Sandbox Code Playgroud)
现在这让我有点害怕.这是否意味着我们只有请求版本0.0.41的请求类型?
我正在尝试通过 WebPack 在浏览器中使用 node_modules。我已经阅读了教程和开始步骤,但被卡住了。
我已经使用 webpack 使用下面的 webpack 配置生成 bundle.js,在 Chrome 浏览器中访问我的 index.html 时出现错误:
Uncaught ReferenceError: require is not defined
at Object.<anonymous> (bundle.js:205)
我必须执行哪些额外步骤才能让浏览器识别需要?
索引.html
<script src="bundle.js"></script>
<button onclick="EntryPoint.check()">Check</button>
Run Code Online (Sandbox Code Playgroud)
索引.js
const SpellChecker = require('spellchecker');
module.exports = {
check: function() {
alert(SpellChecker.isMisspelled('keng'));
}
};
Run Code Online (Sandbox Code Playgroud)
包.json
{
"name": "browser-spelling",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"node-loader": "^0.6.0",
"spellchecker": "^3.3.1",
"webpack": "^2.2.1"
}
}
Run Code Online (Sandbox Code Playgroud)
webpack.config.js
module.exports = {
entry: './index.js',
target: 'node',
output: {
path: './',
filename: 'bundle.js',
libraryTarget: 'var',
library: …Run Code Online (Sandbox Code Playgroud) 我们有一个 Dockerfile,在某个时候不希望缓存发生。
目前我们正在使用
ENV CACHE_BUST=$($RANDOM)
经过进一步检查,有趣的是,它被缓存了:
Step 1/1 : ENV CACHE_BUST=$($RANDOM)
---> Using cache
有没有办法从 Dockerfile 内部破坏缓存,而无需build-argdocker build . --build-arg CACHE_BUST=$(date +%s)在构建步骤中传入唯一的(Like )?
angular ×6
typescript ×2
api ×1
bundle ×1
constructor ×1
docker ×1
dockerfile ×1
javascript ×1
json ×1
ngoninit ×1
node.js ×1
npm ×1
package.json ×1
python ×1
python-3.x ×1
webpack ×1