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 ...
随机推荐
- python深入走路
Python描述符(descriptor)解密 http://www.geekfan.net/7862/
- linux命令(3):复制,剪切(文件和文件夹)
一:文件命令:cp,mv linux 怎么样复制文件夹内所有文件到另一个文件夹? cp -Rf /home/user1/* /root/temp/ 将 /home/user1目录下的所有东西拷到/ ...
- 子iframe 怎么调用 父级的JS函数
window.parent.父级函数名();
- 基于HTML5的多张图片上传
图片上传之前也有写过demo,不过是单张上传的,最近有个业务需求是需要多张上传的,于是乎从新改写了一下 HTML结构: 1 2 3 4 <div class="container&qu ...
- 第一个APP:IOS做简单运算的计算器
步骤: 1.打开Xcode,单机Creat a new Xcode project 2.左边选择ios下Application,右边选择single view Application 3.填写项目名称 ...
- Nginx+Keepalived主主负载均衡服务器
Nginx+keepalived主主负载均衡服务器测试实验环境: 主Nginx之一:192.168.11.27主Nginx之二:192.168.11.28Web服务器一:192.168.11.37We ...
- QT中QWidget、QDialog QMainWindow
继承关系:在Qt中所有的类都有一个共同的基类QObject ,QWidget直接继承与QPaintDevice类,QDialog.QMainWindow.QFrame直接继承QWidget 类. QW ...
- struts (三)
1. <action name="test" class="com.gc.Test"> <result name="success& ...
- java利用过滤器实现编码的转换,内容输出的替换
在页面建个表单 <form action="login.do" method="post"> <input type="text&q ...
- c# list排序的三种实现方式
用了一段时间的gridview,对gridview实现的排序功能比较好奇,而且利用C#自带的排序方法只能对某一个字段进行排序,今天demo了一下,总结了三种对list排序的方法,并实现动态传递字段名对 ...