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 ...
随机推荐
- P6378-[PA2010]Riddle【2-SAT】
正题 题目链接:https://www.luogu.com.cn/problem/P6378 题目大意 给出\(n\)个点\(m\)条边的一张无向图,图中有\(k\)种颜色的点. 要求每种颜色选择一个 ...
- kubelet源码分析——kubelet简介与启动
kubelet是k8s集群中一个组件,其作为一个agent的角色分布在各个节点上,无论是master还是worker,功能繁多,逻辑复杂.主要功能有 节点状态同步:kublet给api-server同 ...
- 【Markdown】Shell命令高亮显示
[问题]shell命令,黏贴到简书的代码块上,#后面的命令显示成被注释掉的效果 image.png [目的]高亮显示shell命令 [方案1]在代码块标示符后,加上此代码块所用的语言名(请注意要用小写 ...
- 前端VUE基于gitlab的CI_CD
目录 CI 1.Gitlab的CI 1.1 GitLab-Runner 1.2 .gitlab-ci.yml 1.3 配置.gitlab-ci.yml 1.3.1 Pipeline概念 1.3.2 S ...
- C 标准库函数手册摘要
<stdlib.h> int abs( int value ); long int labs( long int value ); 返回参数的绝对值 int rand( void ); v ...
- Succeed_School
# Author kevin_hou class School(object): def __init__(self,name,addr): self.name = name self.addr = ...
- SpringBoot 01 hello world 01
hello world项目结构: pom中配置的依赖相当于spring boot的可安装插件,需要下载的依赖直接在里边配置. 目前用到的每个注解: 1.主程序中 @SpringBootApplicat ...
- FastAPI 学习之路(四十六)WebSockets(二)
上一篇文章,我们分享了WebSockets一些入门的,我们这节课,在原来的基础上,对于讲解的进行一个演示.我们最后分享了依赖token等.首先我们对上次的代码进行调整. 我们之前分享FastAPI 学 ...
- 【Java虚拟机9】类加载器之命名空间详解
前言 前面介绍类加载器的时候,介绍了一下命名空间这个概念.今天就通过一个例子,来详细了解一下[类加载器的命名空间].然后通过这个例子,我们可以总结一下双亲委托模型的好处与优点. 例1(不删除class ...
- Map中getOrDefault()与数值进行比较
一般用哈希表计数时,value类型通常为Integer.如果想比较某个key出现的次数,使用get(key)与某个数值进行比较是有问题的.当哈希表中并不包含该key时,因为此时get方法返回值是nul ...