If u using controller & controllerAs in directive, then the link()'s 4th param 'controller' will refer to the controller u defined before.

 function MessageController(){
var vm = this; vm.message = "Hello";
} function greeting(){
function link(scope, element, attrs, ctrl){
ctrl.message = ctrl.message + ' ' + scope.name;
} return {
controller: 'MessageController',
controllerAs: 'vm',
link: link,
scope: {
name: '@'
},
template: '<h1>{{vm.message}}</h1>'
};
} angular.module('app', [])
.directive('greeting', greeting)
.controller('MessageController', MessageController);
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body ng-app="app">
<greeting name="Zhentian"></greeting>
</body>
</html>

[AngularJS] Accessing The View-Model Inside The link() When Using controllerAs的更多相关文章

  1. 使用View Model从表现层分离领域模型

    本文来自:http://www.cnblogs.com/shanyou/archive/2010/04/03/1703501.html Model-View-Controller(模型-视图-控制器, ...

  2. WPF MVVM 架构 Step By Step(6)(把actions从view model解耦)

    到现在为止,我们创建了一个简单的MVVM的例子,包含了实现了的属性和命令.我们现在有这样一个包含了例如textbox类似的输入元素的视图,textbox用绑定来和view model联系,像点击but ...

  3. 在ASP.NET MVC中使用Knockout实践04,控制View Model的json格式内容

    通常,需要把View Model转换成json格式传给服务端.但在很多情况下,View Model既会包含字段,还会包含方法,我们只希望把字段相关的键值对传给服务端. 先把上一篇的Product转换成 ...

  4. 在ASP.NET MVC中使用Knockout实践02,组合View Model成员、Select绑定、通过构造器创建View Model,扩展View Model方法

    本篇体验使用ko.computed(fn)计算.组合View Model成员.Select元素的绑定.使用构造器创建View Model.通过View Model的原型(Prototype)为View ...

  5. Qt中的View Model模型

    原始日期: 2016-08-17 21:19 Qt中的View主要有三种QListView,QTreeView, QTabelView 而对应的Model是:QStringListModel, QAb ...

  6. Core Mvc传值ViewData、ViewBag和return view(model)

    先定义一个Model类Student namespace Lession.Models { public class Student { public string Name { get; set; ...

  7. Binding a Xamarin.Forms WebView to ReactiveUI View Model using Custom Type Converters

    引用:https://jamilgeor.com/binding-a-xamarin-forms-webview-to-reactiveui-view-model-using-custom-type- ...

  8. backbone.js 教程(1) View & Model & Collection

    Backbone.js Overview 它由Jeremy Ashkenas开发,最初发行于2010-10-13 它是一个轻量的JavaScript类库,只依赖于underscore.js,非强制依赖 ...

  9. [AngularJS] Accessing Services from Console

    Using the Chrome console, you can access your AngularJS injectable services. This is down and dirty ...

随机推荐

  1. ThinkPHP HTML标签代码和UBB互相转换

    1.UBB 转为 HTML TP的扩展里面自带一个ubb方法,用这个方法就能把用户输入的ubb格式代码转换为HTML标签的代码.这里用到的基本知识就是正则表达式啦,今天先不讲正则表达式. 来看一下TP ...

  2. WebApi(一)-实现跨域返回格式支持json

    1.创建webapi

  3. fineuploader 上传jquery 控件

    fineuploader 昨天用的一个jquery插件. 可参考这篇文章以前写的 file-uploader  跟 这个跟里面介绍的2个jquery 插件相比.觉得更强大写..版本号都3.9 了….. ...

  4. httpclient 超时设置

    最近项目客户反应超时经常出现:现已经总结超时设置: 使用是apache的HttpClient: DefaultHttpClient:请求超时httpclient.getParams().setPara ...

  5. Eclipse 项目有红感叹号、小红叉

    红感叹号: 问题原因]:工程中classpath中指向的包路径错误 [解决办法]:右键项目名称 BuildPath ---> Configure Build Paht...中,然后上面有几个选项 ...

  6. 5个提升Google Chrome浏览器运行速度的技巧

    尽管有无数个喜欢Google Chrome  浏览器的理由,其中就包括,Chrome已经够快了,但Google Chrome的内存占用而导致的速度拖累还是广受诟病,这种弊端在windows下尤为明显, ...

  7. VM Depot 中国上的 Bitnami 镜像更新至 Ubuntu 14.04 LTS

     发布于 2014-08-13 作者 陈 忠岳 随着越来越多中国本地镜像源源不断地加入,  VM Depot 中国站点也在日益壮大(http://msopentech.com/?p=865871) ...

  8. 【转】Ubuntu14.04搭建安装svnserver

    原文网址:http://www.cnblogs.com/blfshiye/p/5168028.html 前两天,公司准备搭建一个svnserver,供大家使用.于是.就先装了一个Ubuntu系统,然后 ...

  9. (转载)vsftpd简易配置

    (转载)http://licong.blog.51cto.com/542131/145748/ 写篇关于vsftp配置的文章,加深自己的记忆,便于自己查阅,同时也希望能给其他需要的朋友一点借鉴.本文如 ...

  10. (转载)PHP json_encode() 函数介绍

    (转载) 在 php 中使用 json_encode() 内置函数(php > 5.2)可以使用得 php 中数据可以与其它语言很好的传递并且使用它. 这个函数的功能是将数值转换成json数据存 ...