是否可以 ?或者我应该结束循环并开始另一个循环?
foreach($array as $i)
{
if (something)
// Go back
}
Run Code Online (Sandbox Code Playgroud) 尝试与@Output 事件发射器进行子级与父级通信,但这里不起作用的是子组件
import { Component, OnInit, Output, Input, EventEmitter } from '@angular/core';
@Component({
selector: 'app-emiter',
templateUrl: './emiter.component.html',
styleUrls: ['./emiter.component.css']
})
export class EmiterComponent implements OnInit {
@Output() emitor: EventEmitter<any>
constructor() { this.emitor = new EventEmitter()}
touchHere(){this.emitor.emit('Should Work');
console.log('<><><><>',this.emitor) // this comes empty
}
ngOnInit() {
}
}
Run Code Online (Sandbox Code Playgroud)
这是 html 模板
<p>
<button (click)=" touchHere()" class="btn btn-success btn-block">touch</button>
</p>
Run Code Online (Sandbox Code Playgroud)
touchHere 中的 console.log 即使我把它放在父组件中它也没有显示任何内容它也没有显示父组件
import { Component , OnInit} from '@angular/core';
// service I use for other stuff//
import { SenderService } …Run Code Online (Sandbox Code Playgroud) 设法安装和设置Ionic的本机深层链接模块。
即使在完全关闭的寒冷状态下,应用程序也可以正常加载。
但是,我的路线无法将我带到正确的页面。它仅显示应用程序所在的最后一页,如果它从冷状态启动应用程序,则显示主页。
app.component.ts
...
import { Deeplinks } from '@ionic-native/deeplinks';
import { Detail1Page } from '../pages/layout/app1/detail1/detail1';
...
constructor(private deeplinks: Deeplinks.........
...
this.platform.ready().then(() => {
this.splashScreen.hide();
this.deeplinks.route({
'/item/:itemId': Detail1Page
}).subscribe((match) => {
console.log('Successfully matched route', JSON.stringify(match));
}, (nomatch) => {
console.error('Got a deeplink that didn\'t match', JSON.stringify(nomatch));
});
}
...
Run Code Online (Sandbox Code Playgroud)
控制台日志显示:
Successfully matched route {"$args":{"itemId":"9"},"$link":{"path":"/item/9","queryString":"","fragment":"","host":"my.app.com","url":"https://my.app.com/item/9","scheme":"https"}}
Run Code Online (Sandbox Code Playgroud)
app.module.ts
...
import { Deeplinks } from '@ionic-native/deeplinks';
...
providers: [
Deeplinks,
...
Run Code Online (Sandbox Code Playgroud)
detail1.ts
...
this.itemId = this.navParams.get('itemId');
...
Run Code Online (Sandbox Code Playgroud)
非常感谢您的帮助-整天都在努力:)
由于在开发项目时学习了Angular 2,我没有采用我应该具备的路由.我有一个main.js文件引导一个组件,另一个main2.js文件引导第二个组件(我现在知道我应该从一个页面路由它们,但我们在项目中很远,它会导致一个备份((必要时会这样做)).我正在尝试使用webpack捆绑"可加载性"的代码(sp?).
这是我的webpack.config.js文件:
var path = require( 'path' );
var webpack = require( 'webpack' );
module.exports = {
entry: "./main",
output: {
path: __dirname,
filename: "./dist/bundle.js"
},
resolve: {
extensions: ['.js', '.ts']
},
module: {
loaders: [{
test: /\.ts/, loaders: ['ts-loader'], exclude: /node_modules/
}]
}
};
Run Code Online (Sandbox Code Playgroud)
是否可以定义两个入口点,如下所示:
var path = require( 'path' );
var webpack = require( 'webpack' );
module.exports = {
entry: "./main",
output: {
path: __dirname,
filename: "./dist/bundle.js"
},
resolve: {
extensions: ['.js', '.ts']
},
module: {
loaders: …Run Code Online (Sandbox Code Playgroud) 我有两个日期时间选择器(从,到)。我需要得到分钟(1505分钟)和日期和时间(2天1小时35分钟)之间的FROM和TO日期之间的差异。
我使用moment.js
var now = moment('2018-03-28 14:02');
var end = moment('2018-06-02 00:00'); // another date
var duration = moment.duration(end.diff(now));
var days = duration.asDays();
console.log(days) //65.41527777777777
Run Code Online (Sandbox Code Playgroud)
这里输出的65.41527777777777地方65是正确天,但如何转换41527777777777到小时和分钟。如果我这样做,0,41527777777777 * 24 = 9,96666666648我会得到9个小时,0,96666666648 * 60 = 57这又是正确的区别
65 day, 9 hour and 57 min
Run Code Online (Sandbox Code Playgroud)
但是,有什么方法可以直接使用moment.js做到这一点吗?
谢谢
我是角度世界的初学者,我使用的是角度材料的“排序标头”组件,在 API 选项卡(https://material.angular.io/components/sort/api)上有一个叫做服务的东西,并且我想使用它们,但我不明白如何使用它。
例如:
在“排序标题”的 API 选项卡上或(https://material.angular.io/components/sort/api)
我想使用“MatSortHeaderIntl”服务,它有一些属性,例如 - sortDescriptionLabel
所以请告诉我如何使用“MatSortHeaderIntl”服务的“sortDescriptionLabel”属性。
谢谢。
单击按钮时我试图重定向到另一个页面(Page-II),但不幸的是另一个页面组件加载在同一页面(Page-I)上。到目前为止我尝试过的:
应用程序组件.html
<button (click)="register()"
mat-raised-button class="searchButton" type="button">Register</button>
<button (click)="profile()"
mat-raised-button class="searchButton" type="button">Profile</button>
<router-outlet></router-outlet>
Run Code Online (Sandbox Code Playgroud)
应用程序路由.module.ts
const routes: Routes = [{
path : 'register',
component : RegisterComponent
},
{
path : 'profile',
component : ProfileComponent
}];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
Run Code Online (Sandbox Code Playgroud)
应用程序组件.ts
import { Component , OnInit } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'app';
constructor(private router: Router …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的应用程序中创建一个路由,我想允许管理员输入 url 作为
http://localhost:4200/#/start/referral_code=jk
Run Code Online (Sandbox Code Playgroud)
然后在组件内部获取referral_codeie的值jk。
在我的路线中,我将路线定义为
{ path: 'start/:referral_code', component: StartPageComponent },
Run Code Online (Sandbox Code Playgroud)
我想要实现的是,当管理员输入上面提供URL的内容时,referral_code应该在指定的组件内接收变量的值StartPageComponent。我在里面添加了以下内容ngOnInit()如下
this.activatedRoute.params.subscribe((params: any) => {
if (params) {
let refCode = params.referral_code;
console.log(refCode);
}
});
Run Code Online (Sandbox Code Playgroud)
一旦我在上面输入,URL后面的部分就=被删除了=,结果网址更改为
http://localhost:4200/#/start/referral_code
Run Code Online (Sandbox Code Playgroud)
并在组件内部console.log(refCode);显示字符串referral_code而不是referral_codeie的值jk。
我不能使用QueryParams,http://localhost:4200/#/start?referral_code=jk也不能更改 urlhttp://localhost:4200/#/start/referral_code=jk
我很感激任何帮助。
我目前在Scotch.io上学习使用NodeJS,Express,PostgreSQL和Sequelize然后我遇到了这个:
'use strict';
var fs = require('fs');
var path = require('path');
var Sequelize = require('sequelize');
var basename = path.basename(module.filename);
var env = process.env.NODE_ENV || 'development';
var config = require(__dirname + '/../config/config.json')[env];
var db = {};
if (config.use_env_variable) {
var sequelize = new Sequelize(process.env[config.use_env_variable]);
} else {
var sequelize = new Sequelize(config.database, config.username, config.password, config);
}
fs
.readdirSync(__dirname)
.filter(function(file) {
return (file.indexOf('.') !== 0) && (file !== basename) & (file.slice(-3) === '.js');
})
.forEach(function(file) {
var model = sequelize['import'](path.join(__dirname, file));
db[model.name] …Run Code Online (Sandbox Code Playgroud) 我正在使用 VSCode(最新版本),有时我会使用分割面板。
我找不到一种方法来实现与Ctrl + Tab面板相同的行为。
它目前将我发送到当前面板中的另一个选项卡。
我有一个$scope.product变量.在我看来,我有这个:
<a ng-href="/{{ gender }}/{{ section }}/{{ product.slug }}">{{ product.name }}</a>
Run Code Online (Sandbox Code Playgroud)
如果$scope.product.vendor存在,我希望它显示
{{ product.vendor.name }} - {{ product.name}} 例如:VendorName - ProductName
别的,只是表明
{{ product.name }} 例如:ProductName
我如何在视图中执行此操作?或者应该在其他地方完成?
PS是我的HTML的简化版本.我已经为周围的div有另一个变量的switch语句,所以这实际上是这样的:
<h3 ng-switch="locale">
<a ng-href="/{{ locale }}/{{ gender }}/{{ section }}/{{ product.slug }}" ng-switch-when="cn">{{ product.name }}</a>
<a ng-href="/{{ gender }}/{{ section }}/{{ product.slug }}" ng-switch-default>{{ product.name }}</a>
</h3>
Run Code Online (Sandbox Code Playgroud) 我正在使用此 API来获取用户的联系人。我会得到与联系人关联的标签,但在文档中找不到它。我不是在谈论标签属性,比如<gContact:relation label="drinking buddy">Marvin</gContact:relation>但这种标签:
如果有人能告诉我在哪里可以找到这个标签。
我有一个项目,我需要通过按钮将文档添加到 API
但现在我只需要按钮打开文件选择器,让我选择文件并返回它的名称。
我已将此按钮分配给该事件。
那么有人可以帮我打开文件查找器的代码吗?我是 Angular 的初学者。
按钮:
<button (click)="myEvent($event)">Add Document</button>
事件:
myEvent (event) {
console.log(event); }
Run Code Online (Sandbox Code Playgroud)
预先感谢,大卫。
angular ×7
javascript ×4
angularjs ×1
deep-linking ×1
events ×1
foreach ×1
google-api ×1
html ×1
ionic3 ×1
momentjs ×1
node.js ×1
php ×1
sequelize.js ×1
typescript ×1
web ×1
webpack ×1