[AngularJS] Accessing The View-Model Inside The link() When Using controllerAs
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的更多相关文章
- 使用View Model从表现层分离领域模型
本文来自:http://www.cnblogs.com/shanyou/archive/2010/04/03/1703501.html Model-View-Controller(模型-视图-控制器, ...
- WPF MVVM 架构 Step By Step(6)(把actions从view model解耦)
到现在为止,我们创建了一个简单的MVVM的例子,包含了实现了的属性和命令.我们现在有这样一个包含了例如textbox类似的输入元素的视图,textbox用绑定来和view model联系,像点击but ...
- 在ASP.NET MVC中使用Knockout实践04,控制View Model的json格式内容
通常,需要把View Model转换成json格式传给服务端.但在很多情况下,View Model既会包含字段,还会包含方法,我们只希望把字段相关的键值对传给服务端. 先把上一篇的Product转换成 ...
- 在ASP.NET MVC中使用Knockout实践02,组合View Model成员、Select绑定、通过构造器创建View Model,扩展View Model方法
本篇体验使用ko.computed(fn)计算.组合View Model成员.Select元素的绑定.使用构造器创建View Model.通过View Model的原型(Prototype)为View ...
- Qt中的View Model模型
原始日期: 2016-08-17 21:19 Qt中的View主要有三种QListView,QTreeView, QTabelView 而对应的Model是:QStringListModel, QAb ...
- Core Mvc传值ViewData、ViewBag和return view(model)
先定义一个Model类Student namespace Lession.Models { public class Student { public string Name { get; set; ...
- 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- ...
- backbone.js 教程(1) View & Model & Collection
Backbone.js Overview 它由Jeremy Ashkenas开发,最初发行于2010-10-13 它是一个轻量的JavaScript类库,只依赖于underscore.js,非强制依赖 ...
- [AngularJS] Accessing Services from Console
Using the Chrome console, you can access your AngularJS injectable services. This is down and dirty ...
随机推荐
- 【python】只执行普通除法:添加 from __future__ import division
from __future__ import division 注意future前后是两个下划线
- MAYA 多线程
''' Usage: def timerTest(): print 'Hello World!' #create and start a timer timer = Timer(30, timerTe ...
- [python]获取字符串类型
>>>type(value) <class 'type'> >>>isinstance(value,type) True/False
- 将小度WiFi改造为无线网卡(小度WiFi能够接收WiFi信号)
安装官方的小度WiFi的驱动器,只能让它当做无线信号的发射装置,但是我想通过小度WiFi让我的台式电脑能都接收无线信号,于是经过一番折腾终于成功了.我的是win7. 小度WiFi无法接受无线信号,不能 ...
- Quartz1.8.5例子(七)
/* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...
- golang入门-- 一个2D的图形库学习
此库叫gg,源码在github. 1.获取源码并安装到本地: 首先要安装git (传送门) : https://git-scm.com/download/ 然后就可以通过 go get 命令从 ...
- Netty高性能之道
1. 背景 1.1. 惊人的性能数据 最近一个圈内朋友告诉我,通过使用Netty4 + Thrift压缩二进制编解码技术,他们实现了10W TPS(1K的复杂POJO对象)的跨节点远程服务调用.相比于 ...
- 【POJ1330】Nearest Common Ancestors(树链剖分求LCA)
Description A rooted tree is a well-known data structure in computer science and engineering. An exa ...
- 【POJ1082】Calendar Game (博弈)
[题目] Description Adam and Eve enter this year's ACM International Collegiate Programming Contest. La ...
- C API向MySQL插入批量数据的快速方法——关于mysql_autocommit
MySQL默认的数据提交操作模式是自动提交模式(autocommit).这就表示除非显式地开始一个事务,否则每个查询都被当做一个单独的事务自动执行.我们可以通过设置autocommit的值改变是否是自 ...