service是单例模式的

新增Service类 search.service.ts

import {Injectable} from '@angular/core';

@Injectable()
export class SearchService {
searchArea: string;
constructor() {
this.searchArea='广州市';
}
}

新增Service模块 service.module.ts

import {NgModule} from '@angular/core';
import {SearchService} from "./search.service"; const services = [
SearchService
]; @NgModule({
imports: [],
exports: [],
declarations: [],
providers: [...services]
})
export class ServiceModule {
}

修改App根模块 app.module.ts

import {NgModule} from '@angular/core';
import {ServiceModule} from "./service/service.module"; @NgModule({
declarations: [],
imports: [
ServiceModule
],
bootstrap: [],
entryComponents: [],
providers: []
})
export class AppModule { }

在其他ts文件中使用该Service的方法

import {Component} from '@angular/core';
import {NavController} from "ionic-angular";
import {SearchService} from "../../../app/service/search.service"; @Component({
templateUrl: 'choice.html',
}) export class SearchChoicePage {
constructor(public navCtrl: NavController, private searchService: SearchService) {
} returnArea(name: string) {
this.searchService.searchArea = name;
this.navCtrl.pop();
} }

  

原创文章,欢迎转载,转载请注明出处!

Ionic3 新增 Service的更多相关文章

  1. 扩展服务 修改新增Service的默认主题

    问题描述:想要在F:\PHPnow-1.5.6\htdocs\yt\Yourphp\Tpl\      目录下新增一个Service\Default(A)   和Service\new(B) 两个主题 ...

  2. Kong命令(二)service

    service介绍: service 是声明了一组name.host.port.protocol等配置的函数.可以绑定route.upstream上下游服务.并且对于route.upstream可以绑 ...

  3. 【Traefik二次开发】服务 Service 开发

    Service 定义 https://doc.traefik.io/traefik/routing/services/ The Services are responsible for configu ...

  4. 走进spring之springmvc实战篇(二)

    本篇继篇一之后加入了jdbc并使用了注解 篇一进行了对spingmvc的基础配置http://www.cnblogs.com/liuyanhao/p/4798989.html 首先让我们先了解下注解的 ...

  5. 基于Autofac, Castle.DynamicProxy的动态WCF解决方案(原创)

    本方案解决了下面3个主要的问题: 1.减少配置,为了避免每次新增service都需要去修改配置文件,包括服务器端跟各个客户端的. 2.能够使用函数重载,泛型函数,以及泛型类. 3.使项目能够快速地在w ...

  6. Web服务器常用设置

    1.Tomcat浏览目录 找到安装目录下的文件/conf/web.xml,  找到以下配置节,将parame-value设置为true即可 <init-param>             ...

  7. ionic 运行过程中动态切换API服务器地址

    ionic 运行过程中动态切换API服务器地址 keywords: ionic,phonegap,cordova,网络制式,动态切换,变更,API,服务器地址,$resource,localstora ...

  8. Centos部署nagios+apache实现服务器监控

    1.Nagios介绍 nagios是 一款功能强大的网络监视工具,它可以有效的监控windows.linux.unix主机状态以及路由器交换机的网络设置,打印机工作状态等,并将状态出 现异常的服务及时 ...

  9. Spring-cloud (七)自定义HystrixCommand

    前提 1.在继续学习Hystrix之前,向关注本人博客的各位致歉 由于之前的项目起名以及服务之间的名称不是很规范,所以我修改了这些名称方便后来的代码管理,这些代码可以在本人github中找到,这里贴出 ...

随机推荐

  1. 搜狐畅游一面(c++)

    上来是个小姐姐,有点懵.. 1.  介绍 2.  项目 3.  实习 4.  用的协议 tcp和udp的协议 5.  select 和epoll(忘了) 6. 数据库的隔离级别, 死锁, 怎么避免死锁 ...

  2. 分享一个小设置-项目启动时服务器指向本地IIS

    背景,在X公司做的一个网站登录时需要域名的支持,就是说浏览器地址栏在localhost+端口号的形式下无法实现登录(必须是xxxx域名的形式), 但是很多时候都会先在线下进行测试,既然本地没有线上的环 ...

  3. 文本文档中各字母出现次数汇总(java)

    package 字母频率统计; import java.io.*; public class Inputfile { public static void main(String args[]) { ...

  4. Redis Sentinel 集群搭建常见注意事项

    我的配置: 1个master,1个slave,3个sentinel 搭建的过程网上已经有很多了,这里列几个重点关注: 修改sentinel.conf的protected-mode与redis.conf ...

  5. rbac组件权限按钮,菜单,可拔插

      1.通用模板 overflow: auto; //在a和b模板中进行切换 a 模板 :左侧菜单跟随滚动条 b模板  左侧以及上不动 **** <!DOCTYPE html> <h ...

  6. 学习yii2.0——依赖注入

    依赖注入 依赖注入是一种设计模式,可以搜索“php依赖注入”,这里不阐述了. yii框架的依赖注入 Yii 通过 yii\di\Container 类提供 DI 容器特性. 它支持如下几种类型的依赖注 ...

  7. Linux (Redhat / Fedora / CentOS) 更改 hostname 的方式

    Linux (Redhat / Fedora / CentOS) 更改 hostname 的方式 [蔡宗融個人網站]https://www.ichiayi.com/wiki/tech/linux_ho ...

  8. 生成短链接的URL

    假设你想做一个像微博短链接那样的短链接服务,短链接服务生成的URL都非常短例如: http://t.cn/E70Piib, 我们应该都能想到链接中的E70Piib对应的就是存储长链接地址的数据记录的I ...

  9. python3 九九乘法表打印花式操作(然并卵)

    # 九九乘法表# 方法一# for i in range(1, 10):# for j in range(1, i+1):# print('{}x{}={}\t'.format(i, j, i*j), ...

  10. Velocity ${} 和$!{}、!${}区别

    前言 在使用Velocity时经常会看到三种使用变量的情况 情况一:${name} 情况二:$!{name} 情况三:!${name} 那么三者之间到底有什么区别呢?莫慌!!!哈哈 情况一:${nam ...