Skip to content

Commit

Permalink
url传参
Browse files Browse the repository at this point in the history
  • Loading branch information
xuefeng committed Jan 17, 2020
1 parent a78557b commit 88f6e8d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="box-root">
<div class="box-top">
<ms-search-box (onClick_Search)="onClick_Search($event)"></ms-search-box>
<ms-search-box [inputText]="this.viewData.query" (onClick_Search)="onClick_Search($event)"></ms-search-box>
<div class="box-btns">
<!-- <div class="btn" *ngIf="viewData.screens.length<4" (click)="onClick_addScreen()">-->
<!-- <img class="btn-add" src="assets/img/add.png"/>-->
Expand Down
25 changes: 22 additions & 3 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {Component} from '@angular/core';
import { Component, OnInit, ViewChild } from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {MSServiceService} from './msservice.service';
import {BaseView} from './base-view';
import {MSConfig} from './MSConfig';
import hotkeys from 'hotkeys-js';
import { MSSearchBoxComponent } from './components/mssearch-box/mssearch-box.component';

interface IScreen {
isShow: boolean;
Expand All @@ -15,18 +17,22 @@ interface IScreen {

interface IViewData {
screens: IScreen[];
query?: string;
}

@Component({
selector: 'MS-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent extends BaseView<IViewData> {
export class AppComponent extends BaseView<IViewData> implements OnInit{
title = 'MoreSearch';

constructor(public msService: MSServiceService) {
@ViewChild(MSSearchBoxComponent) searchBox: MSSearchBoxComponent;

constructor(public msService: MSServiceService,public router: ActivatedRoute) {
super({
query: '',
screens: [/*{
isShow: false,
index: 4,
Expand Down Expand Up @@ -67,6 +73,19 @@ export class AppComponent extends BaseView<IViewData> {
};
}

ngOnInit() {
this.router.queryParams.subscribe(params => {
let query = params['query'];
if(query){
this.viewData.query = query;
if(this.searchBox){
this.searchBox.viewData.inputText = query;
}
this.onClick_Search(query);
}
});
}

onClick_Search(inputText: string) {
this.msService.search(inputText);
}
Expand Down
6 changes: 5 additions & 1 deletion src/app/components/mssearch-box/mssearch-box.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {Component, EventEmitter, OnInit, Output, Input} from '@angular/core';
import {BaseView} from '../../base-view';
import hotkeys, {HotkeysEvent} from 'hotkeys-js';

Expand All @@ -15,6 +15,7 @@ interface IViewData {
export class MSSearchBoxComponent extends BaseView<IViewData> implements OnInit {

@Output() onClick_Search: EventEmitter<string> = new EventEmitter<string>();
@Input() inputText;

constructor() {
super({
Expand All @@ -31,6 +32,9 @@ export class MSSearchBoxComponent extends BaseView<IViewData> implements OnInit
}, (keyEvent: KeyboardEvent, hkevent: HotkeysEvent) => {
this.onClick_search();
});
if(this.inputText){
this.viewData.inputText = this.inputText;
}
}

onClick_search() {
Expand Down

0 comments on commit 88f6e8d

Please sign in to comment.