Part 33 Angular nested scopes and controller as syntax
Working with nested scopes using $scope object : The following code creates 3 controllers - countryController, stateController, and cityController. All of these have set name property on the $scope object.
Now we want to display Country, State and City names as shown below.

To get the output as shown above, we will have the following HTML in our view. name property retrieves the correct value as expected. However, the code is bit confusing.
Now let us say we want to display the names as shown below.

To achieve this modify the HTML in the view as shown below. Notice we are using $parent to get the name property value of the immediate parent controller. To get the name property value of the grand parent, we are using $parent.$parent. This can get very confusing if you have many nested controllers and as a result the code gets less readable.
Let us see how things change when we use CONTROLLER AS syntax. First change the angular code to support CONTROLLER AS syntax. Notice we are not using $scope anymore with in our controllers, instead, we are using "this" keyowrd.
With in the view, use CONTROLLER AS syntax. With this change, we are able to use the respective controller object and retrieve name property value. Now there is no need to juggle with $parent property. No matter how deep you are in the nested hierarchy, you can very easily get any controller object name property value. The code is also much readable now.
Part 33 Angular nested scopes and controller as syntax的更多相关文章
- angular controller as syntax vs scope
今天要和大家分享的是angular从1.2版本开始带来了新语法Controller as.再次之前我们对于angular在view上的绑定都必须使用直接的scope对象,对于controller来说我 ...
- Part 32 AngularJS controller as syntax
So far in this video series we have been using $scope to expose the members from the controller to t ...
- Angular动态注册组件(controller,service...)
使用angular的场景一般是应用类网站 这也意味着会有很多的controller,service,directive等等 正常情况下我们要把这些内容一次性下载并注册,由于文件较多,对首次加载的效率影 ...
- 10.1 Nested vectored interrupt controller (NVIC) 嵌套矢量中断控制器
特点 60个可屏蔽中断通道(不包含16个Cortex™-M3的中断线): 16个可编程的优先等级(使用了4位中断优先级): 低延迟的异常和中断处理: 电源管理控制: 系统控制寄存器的实现: 1. 中断 ...
- 33.AngularJS 应用 angular.module定义应用 angular.controller控制应用
转自:https://www.cnblogs.com/best/tag/Angular/ AngularJS 模块(Module) 定义了 AngularJS 应用. AngularJS 控制器(Co ...
- angular语法:Controller As
这个东东我觉得很好哟. 数据可以在同一个页面的不同的controller之间自由穿梭... 当然, https://thinkster.io/a-better-way-to-learn-angular ...
- angular学习笔记(三十)-指令(10)-require和controller
本篇介绍指令的最后两个属性,require和controller 当一个指令需要和父元素指令进行通信的时候,它们就会用到这两个属性,什么意思还是要看栗子: html: <outer‐direct ...
- angular 自定义指令 link or controller
Before compilation? – Controller After compilation? – Link var app = angular.module('plunker', []); ...
- Angular中Controller之间的信息传递(第二种办法):$emit,$broadcast,$on
$emit只能向parent controller传递event与data( $emit(name, args) ) $broadcast只能向child controller传递event与data ...
随机推荐
- c++ 的学习 构造函数1
1. 构造函数(也叫构造器),在对象创建的时候自动调用,一般用于完成对象的初始化工作 2.一旦自定义了构造函数,必须用其中一个自定义的构造函数来初始化对象 就是有多个的话 根据参数编译器自行选 ...
- HCNP Routing&Switching之BGP基础
前文我们了解了路由注入带来的问题以及解决方案相关话题,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/15362604.html:今天我们来学习下新的路由协议BG ...
- tomcat unkonwhost
服务器能ping通域名,tomcat死活不行,重启tomcat解决
- Java集合——List,Set,Map总结笔记
1. 集合 Collection 1.1 Java 集合框架 Java 集合框架位于 java.util 包中.Java 集合框架主要包括两种类型的容器,一种是集合(C ...
- 使用mobaXtrem显示CentOS图形
安装环境 yum install -y xorg-x11-xauth xorg-x11-fonts-* xorg-x11-font-utils xorg-x11-fonts-Type1 \mesa-l ...
- Java初步学习——2021.09.24每日总结,第三周周五
(1)今天做了什么: (2)明天准备做什么? (3)遇到的问题,如何解决? 今天学了将数组传递给方法和方法返回数组,其中传递的是数组的引用. 明天把例子做了,尽量把查找也学习了. 遇到了两个问题: 1 ...
- 3DGIS开发使用的开源项目
gdal proj4 vcglib assimp libjpg libpng osg libtess2 cesiumjs glm
- SpringBoot-使用异步
SpringBoot提供了异步的支持,上手使用十分的简单,只需要开启一些注解支持,配置一些配置文件即可! 编写方法,假装正在处理数据,使用线程设置一些延时,模拟同步等待的情况: service: @S ...
- IDA硬编码修改SO,重新打包APK绕过FRIDA反调试
该案例来自看雪 通过IDA修改SO 找到检测点 修改字符串 双击该字符串进入TEXT VIEW 选择 HEX VIEW 修改十六进制 右击EDIT 修改字符 右击 菜单栏-> edit -> ...
- Vim合并行
日常常用到多行合并的功能,记录如下: 第一种, 多行合并成一行,即: AAAAABBBBBCCCCC 合并为:AAAAA BBBBB CCCCC 方法1: normal状态下 3J 其中的3是范围,可 ...