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 ...
随机推荐
- P4022-[CTSC2012]熟悉的文章【广义SAM,dp,单调队列】
正题 题目链接:https://www.luogu.com.cn/problem/P4022 题目大意 给出\(m\)个模板串. 然后\(n\)次询问给出一个串\(S\)要求找到一个最大的\(L\)使 ...
- CF802O-April Fools‘ Problem(hard)【wqs二分,优先队列】
正题 题目链接:https://www.luogu.com.cn/problem/CF802O 题目大意 \(n\)天每条有\(a_i\)和\(b_i\). 每条可以花费\(a_i\)准备至多一道题, ...
- 【问题记录】Java服务发起HTTPS请求报错:PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException
问题报错 今天上线了我开发的一个OAuth2单点登录客户端的实现,在测试系统验证没问题,到生产环境由于单点登录服务端HTTPS协议,报错如下: I/O error on POST request fo ...
- Spring MVC面试复习整理
Spring MVC Spring MVC 是Spring Framework 提供的 web 组件 它的实现基于 MVC 的设计模式:Model(模型层).View(视图层).Controller( ...
- VS2013编译报错——error LNK2001: 无法解析的外部符号 __imp_PathMatchSpecA E:\CaffeProgram\3train_mnist(p)\3train_mnist\gflags.lib(gflags.obj) 3train_mnist
解决方案来自http://blog.csdn.net/yang6464158/article/details/41743641 感谢感谢~~
- 实时获取股票数据,免费!——Python爬虫Sina Stock实战
更多精彩内容,欢迎关注公众号:数量技术宅,也可添加技术宅个人微信号:sljsz01,与我交流. 实时股票数据的重要性 对于四大可交易资产:股票.期货.期权.数字货币来说,期货.期权.数字货币,可以从交 ...
- OGG-如何只同步最近某个时间范围的数据
一.需求,某客户希望使用OGG只同步时间大于2021-02-01日期之后的数据变换 需求如标题所示,如何使用OGG进行配置? 客户环境需要同步的表有几百G,表数据太大了;如果同步所有数据,目标库空间存 ...
- Vue3学习(七)之 列表界面数据展示
一.前言 昨晚可能是因为更新完文章后,导致过于兴奋睡不着(写代码确实太容易让人兴奋了),结果两点多才睡着,大东北果然还是太冷了. 不知道是不是因为膝盖和脚都是冰凉的,所以才导致很晚才能入睡? 刚眯了一 ...
- SharkCTF2021 bybypass&baby_phpserialize题记
(国庆褪10天了 先水一篇) bybypass: payload:?anime_is_bae=hehellotherehoomanllotherehooman baby_phpserialize ro ...
- 【Java虚拟机6】Java内存模型(Java篇)
什么是Java内存模型 <Java虚拟机规范>中曾试图定义一种"Java内存模型"(Java Memory Model,JMM)来屏蔽各种硬件和操作系统的内存访问差异, ...