There are 2 ways to expose the members from the controller to the view - $scope and CONTROLLER AS. The obvious question that comes to our mind at this point is - Why do we have 2 ways of doing the same thing. Which one to use over the other and what are the differences. 

Here are the differences
1. CONTROLLER AS syntax is new and is officially released in 1.2.0. $scope is the old technique and is available since the initial version of angular is released.

2. You can use either one of thes techniques. Both have their own uses. For example, CONTROLLER AS syntax makes your code more readable when working with nested scopes. We discussed this in our previous video.

3. If you want to use $scope it has to be injected into controller function, where as with CONTROLLER AS syntax there is no need for such injection, unless you need it for something else.

Which one to use depends on your personal preference. Some prefer using $scope while others prefer using CONTROLLER AS syntax. One important thing to keep in mind is that, though you are using CONTROLLER AS syntax, behind the scenes angular is still using $scope. Angular takes the controller instance and adds it as a reference on the scope.

<div ng-controller="cityController as cityCtrl">
    {{cityCtrl.name}}
</div>

In the above example since we are using CONTROLLER AS syntax, angular takes cityCtrl which is the instance of cityController and adds it as a reference on the scope. So in the binding expression, you can read it as $scope.cityCtrl.name

最新文章

  1. 前端CSS预处理器Sass
  2. SharePoint创建web application出现“The password supplied with the username was not correct”错误的解决方法
  3. elasticsearch 优化
  4. C语言语法分析器
  5. 【AdaBoost算法】弱分类器训练过程
  6. Oracle 常用SQL技巧(转)
  7. 用 perl 统计 fasta 文件序列的总长
  8. Jython概要
  9. mobox:推进企业文档管理走向信息化之路
  10. linux常用命令--diff
  11. file_get_contents HTTP request failed! Internal Server Error
  12. javascript语言扩展:可迭代对象(5)
  13. Xaramin IOS 开发常见问题
  14. Bitcoin Core钱包客户端的区块数据搬家指南
  15. GPT(保护分区)解决办法
  16. STM32的PWM输入模式设置并用DMA接收数据
  17. The superclass &quot;javax.servlet.http.HttpServlet&quot; was not found on the Java Build Path 解决方法
  18. 微信小程序之可滚动视图 scroll-view 的使用注意
  19. Linux系统_Linux平台“盖茨木马”初步了解
  20. 自定义控件(视图)2期笔记11:View的滑动冲突之 概述

热门文章

  1. ubuntu 安装 gightingale
  2. P2490-[SDOI2011]黑白棋【博弈论,dp】
  3. 从零入门 Serverless | 一文搞懂函数计算及其工作原理
  4. Markdown Syntax Images
  5. C++ 与 Visual Studio 2019 和 WSL(二)
  6. 初学python写个自娱自乐的小游戏
  7. Coursera Deep Learning笔记 改善深层神经网络:超参数调试 Batch归一化 Softmax
  8. 论文解读丨表格识别模型TableMaster
  9. sip信令跟踪工具sngrep
  10. 基于RequestBodyAdvice和ResponseBodyAdvice来实现spring中参数的加密和解密