angular service讲解
controller是相对独立的,也就是说,两个controller之间,内存是不共享的,这个controller是无法访问其他其他controller的属性或者方法的;
<!-- 一个controller -->
<div style="background: yellow;" ng-controller="worldCtrl">
{{author.name}}
<br/> {{author.sex}}
<button ng-click="update()">同步数据</button>
</div> <!-- 另一个controller -->
<div ng-controller="helloCtrl">
{{author.name}}
<br/> {{author.sex}}
<button ng-click="updatePublic()">更新公有变量</button>
</div>
controller.js
var app = angular.module('Hello', []);
app.controller('worldCtrl', function($scope, demoService) {
$scope.author = demoService.publicAuthor;
$scope.update = function() { //同步数据
$scope.author = demoService.publicAuthor;
}
});
app.controller('helloCtrl', function($scope, demoService) {
$scope.author = demoService.publicAuthor;
$scope.updatePublic = function() { //更新您数据
demoService.publicAuthor = {
name: 'fei',
sex: 'female'
}
$scope.author = demoService.publicAuthor;
}
});
service.js
app.service('demoService', function () {
var privateAuthor = { //私有变量
name: 'jack',
sex: 'male'
}
this.publicAuthor = { //共有变量
name: 'rose',
sex: 'female'
}
this.getPriAuthor = function () { //获取私有变量
return publicAuthor;
}
});



end.
angular service讲解的更多相关文章
- Angular Service入门
1.Angular内置service Angular为了方便开发者开发,本身提供了非常多的内置服务.可以通过https://docs.angularjs.org/api/ng/service查看Ang ...
- angular service provider
关于 angular service factory provider 方面有很多,我也来写一篇加深下印象 provider 是一切方法的基础,所以功能也最强,provider 用来定义一个可以被 ...
- thinkphp模型层Model、Logic、Service讲解
thinkphp模型层Model.Logic.Service讲解 时间:2014-08-24 15:54:56 编辑:一切随缘 文章来源:php教程网 已阅读:771 次 js特效 ...
- Angular service, 服务
早上开车上班, 发现车快没油了, 于是拐进加油站. 有一辆出租车也在加油.. Angular service在一个应用里是以单例形式存在的. 这个单例的实例是由service factory( ...
- AngularJS学习之 ngTable 翻页 功能以及利用angular service准备测试数据
1.官网链接 https://github.com/esvit/ng-table#4.0.0 2.安装ngTable后,一定要记得先注册到自己的项目 .module('pttengApp', [ ' ...
- angular service/directive
<html class=" js cssanimations csstransitions" ng-app="phonecatApp" > < ...
- Angular service定义服务
<!DOCTYPE html><html ng-app="myApp"><head lang="en"> <meta ...
- [Angular] Service Worker Version Management
If our PWA application has a new version including some fixes and new features. By default, when you ...
- 第14 章 : Kubernetes Service讲解
Kubernetes Service 本文将主要分享以下四方面的内容: 为什么需要 K8s service: K8s service 用例解读: K8s service 操作演示: K8s servi ...
随机推荐
- NeHe OpenGL教程 第四课:旋转
转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...
- HDFS的运行原理(转)
简介 HDFS(Hadoop Distributed File System )Hadoop分布式文件系统.是根据google发表的论文翻版的.论文为GFS(Google File System)Go ...
- 树莓派用USB蓝牙适配器连接蓝牙设备
下面分享如何配置蓝牙设备.1.连接蓝牙适配到Rpi板子usb上,安装相关蓝牙服务器和驱动 lsusb 查看设备是不是被发现 pi @RaspberryPi ~ $ lsusb Bus 001 Devi ...
- PDF按模板出力,多个PDF合并
const string TEMP_PREXFIX = "Temp_"; ...
- 106、抗锯齿方法paint.setAntiAlias(ture);paint.setFilterBitmap(true))
在Android中,目前,我知道有两种出现锯齿的情况. ① 当我们用Canvas绘制位图的时候,如果对位图进行了选择,则位图会出现锯齿. ② 在用View的RotateAnimation做动画时候 ...
- 为何你的php代码没有写结束标签
PHP闭合标签"?>"在PHP中对PHP的分析器是可选的.但是,如果使用闭合标签,任何由开发者,用户, 或者FTP应用程序插入闭合标签后面的空格都有可能会引起多余的输出.ph ...
- [SQL]开启事物,当两条插入语句有出现错误的时候,没有错误的就插入到表中,错误的语句不影响到正确的插入语句
begin transaction mustt insert into student values(,'kkk','j大洒扫','j','djhdjh') insert into student v ...
- 常见的MIME类型
超文本标记语言文本 .htm,.html text/html 普通文本 .txt text/plain GIF图形 .gif image/gif JPEG图形 .ipeg,.jpg image/jpe ...
- 安装VS2015可能出现的问题以及解决方法
1.语言包问题 在官网上下载的版本是英文版,这就需要自己再去官网上下载一个中文安装包,很快的.不过需要2G内存.官网链接如下所示 https://www.microsoft.com/zh-CN/dow ...
- Begin using git (Part1) - Git的安装与配置
Git提供了适用于Linux, Windows, OSX的客户端, 本节以Windows为例介绍基本安装与配置. 所需工具:msysgit, kdiff3. Get windows installer ...