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. 桂电在线-转变成bootstrap版3(记录学习bootstrap)

    继续上文 正文菜单 html: <!-- 菜单块 --> <div class="on-light" id="menus"> <s ...

  2. PHPExcel导出excel

    如果导出中文时出现乱码,可以尝试将字符串转换成gb2312,例如下面就把$yourStr从utf-8转换成了gb2312: $yourStr = mb_convert_encoding("g ...

  3. 字符串copy

    #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<string. ...

  4. CocoaPods ADD private Spec Repo

    Private Pods CocoaPods is a great tool not only for adding open source code to your project, but als ...

  5. 简谈HashMap、HashTable的区别

    简单的说HashMap是HashTable的轻量级实现,即非线程安全的实现,他们的主要区别概述为: HashMap HashTable (1)允许键和值为null  不允许键或值为null (2)不是 ...

  6. C连接MySQL数据库开发之Windows环境配置及测试

    一.开发环境 Win8.1 64位.VS2013.MySQL5.5.3764位 MySQL安装目录为:C:\Program Files\MySQL\MySQL Server 5.5 二.配置工程环境 ...

  7. Jquery的attr属性

    在JS中设置节点的属性与属性值用到setAttribute(),获得节点的属性与属性值用到getAttribute(),而在jquery中,用一个attr()就可以全部搞定了,赞一个先 ^^ jque ...

  8. iOS内存管理系列之一:对象所有权与引用计数

    当一个所有者(owner,其本身可以是任何一个Objective-C对象)做了以下某个动作时,它拥有对一个对象的所有权(ownership): 1. 创建一个对象.包括使用任何名称中包含“alloc” ...

  9. 【技术贴】SqlServer2008 R2 安装失败提示出现以下错误 服务 MSSQLSERVERO

    Feature: Analysis Services  Status: 失败: 请查看日志了解详细信息  MSI status: 已通过  Configuration status: 失败: 请查看下 ...

  10. Vim识别编码

    http://blog.chinaunix.net/uid-20357359-id-1963123.html