Ionic3 新增 Service
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的更多相关文章
- 扩展服务 修改新增Service的默认主题
问题描述:想要在F:\PHPnow-1.5.6\htdocs\yt\Yourphp\Tpl\ 目录下新增一个Service\Default(A) 和Service\new(B) 两个主题 ...
- Kong命令(二)service
service介绍: service 是声明了一组name.host.port.protocol等配置的函数.可以绑定route.upstream上下游服务.并且对于route.upstream可以绑 ...
- 【Traefik二次开发】服务 Service 开发
Service 定义 https://doc.traefik.io/traefik/routing/services/ The Services are responsible for configu ...
- 走进spring之springmvc实战篇(二)
本篇继篇一之后加入了jdbc并使用了注解 篇一进行了对spingmvc的基础配置http://www.cnblogs.com/liuyanhao/p/4798989.html 首先让我们先了解下注解的 ...
- 基于Autofac, Castle.DynamicProxy的动态WCF解决方案(原创)
本方案解决了下面3个主要的问题: 1.减少配置,为了避免每次新增service都需要去修改配置文件,包括服务器端跟各个客户端的. 2.能够使用函数重载,泛型函数,以及泛型类. 3.使项目能够快速地在w ...
- Web服务器常用设置
1.Tomcat浏览目录 找到安装目录下的文件/conf/web.xml, 找到以下配置节,将parame-value设置为true即可 <init-param> ...
- ionic 运行过程中动态切换API服务器地址
ionic 运行过程中动态切换API服务器地址 keywords: ionic,phonegap,cordova,网络制式,动态切换,变更,API,服务器地址,$resource,localstora ...
- Centos部署nagios+apache实现服务器监控
1.Nagios介绍 nagios是 一款功能强大的网络监视工具,它可以有效的监控windows.linux.unix主机状态以及路由器交换机的网络设置,打印机工作状态等,并将状态出 现异常的服务及时 ...
- Spring-cloud (七)自定义HystrixCommand
前提 1.在继续学习Hystrix之前,向关注本人博客的各位致歉 由于之前的项目起名以及服务之间的名称不是很规范,所以我修改了这些名称方便后来的代码管理,这些代码可以在本人github中找到,这里贴出 ...
随机推荐
- 美团2016秋招笔试B
1.下述解决死锁的方法中,属于死锁预防策略的是? 资源有序分配法 银行家算法:避免死锁 资源有序分配法:预防死锁 资源分配图化简法:检测死锁 撤销进程法:解决死锁 2. 什么是死锁? 如果一个进 ...
- Python常用内建方法:__init__,__new__,__class__的理解
python中所有类都是继承自object, 而object提供了很多原始的内建属性和方法,所以用户自定义的类在Python中也会继承这些内建属性.可以使用dir()函数可以查看,虽然python提供 ...
- 动态规划-LCS最长公共子序列
#include<iostream> #include<cstdio> #include<cstring> #include<string> using ...
- javascript与php与python的函数写法区别与联系
1.javascript函数写法种类: (一).第一种 function test(param){ return 111; } (二).第二种 var test = function(param){ ...
- Springboot+Redis 配置和使用
pom.xml 引入redis 开启缓存 <!-- cache --> <dependency> <groupId>org.springframework.boot ...
- 记一个JS树结构路径查找
var a=[ { "id" : "0000", "text" : "R1", "children" ...
- Of Study
Bacon Reading maketh a full man; conference a ready man; and writing an exact man. And therefore, if ...
- 快速为git添加一个用户
环境:用gitosis-admin管理git的权限. 前期git环境的搭建略去,主要给出快速添加一个用户的步骤: 在git bash中用“ssh-keygen -t rsa”生成公钥私钥,默认放到 “ ...
- [2017BUAA软工助教]团队alpha得分总表
一.累计得分 项目 介绍 采访 贡献分 功能 技术 α例会 α发布 α测试 α展示 α事后 合计 满分 10 10 10 10 10 50 10 10 150 10 280 hotcode5 10 9 ...
- Spring-Boot Banner
下载Spring-Boot源码,目录结构spring-boot-2.1.0.M2\spring-boot-2.1.0.M2\spring-boot-project\spring-boot\src\ma ...