博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[AngularJS] Build Your Own ng-controller Directive
阅读量:6550 次
发布时间:2019-06-24

本文共 2466 字,大约阅读时间需要 8 分钟。

/** * Created by Answer1215 on 12/21/2014. */angular.module('app', [])    .controller('FirstCtrl' , function(){        var vm = this;        vm.message = "I am the first controller";    }).controller('SecondCtrl', function() {        var vm = this;        vm.message = "I am the second controller";    }).directive('customerController', function() {        return{            scope: true, //create a new scope            controller: '@', //assing the directive name to this controller            priority: 500,            restrict: 'A'        }    })
    
{
{first.message}}
{
{second.message}}

 

In angular.js src:

var ngControllerDirective = [function() {  return {    restrict: 'A',    scope: true,    controller: '@',    priority: 500  };}];

 

this.directive = function registerDirective(name, directiveFactory) {    assertNotHasOwnProperty(name, 'directive');    if (isString(name)) {      assertArg(directiveFactory, 'directiveFactory');      if (!hasDirectives.hasOwnProperty(name)) {        hasDirectives[name] = [];        $provide.factory(name + Suffix, ['$injector', '$exceptionHandler',          function($injector, $exceptionHandler) {            var directives = [];            forEach(hasDirectives[name], function(directiveFactory, index) {              try {                var directive = $injector.invoke(directiveFactory);                if (isFunction(directive)) {                  directive = { compile: valueFn(directive) };                } else if (!directive.compile && directive.link) {                  directive.compile = valueFn(directive.link);                }                directive.priority = directive.priority || 0;                directive.index = index;                directive.name = directive.name || name;                directive.require = directive.require || (directive.controller && directive.name);                directive.restrict = directive.restrict || 'EA';                if (isObject(directive.scope)) {                  directive.$$isolateBindings = parseIsolateBindings(directive.scope, directive.name);                }                directives.push(directive);              } catch (e) {                $exceptionHandler(e);              }            });            return directives;          }]);      }      hasDirectives[name].push(directiveFactory);    } else {      forEach(name, reverseParams(registerDirective));    }    return this;  };

 

转载地址:http://mluco.baihongyu.com/

你可能感兴趣的文章
myeclipes启动tomcat6报错解决方案:a configuration error occ
查看>>
新手读懂五线谱
查看>>
什么是相关性以及为什么需要初始化它?
查看>>
c#如何禁止Form窗口调整大小,如何禁止combobox输入
查看>>
Java 编程下线程的生命周期
查看>>
『优秀作品』20个激发灵感的橙色风格网站设计
查看>>
headfirst java ( 第 8 章 )
查看>>
jquery实战视频教程_选项卡效果一
查看>>
[转]简单、通用的JQuery Tab实现
查看>>
iphone4/4s 程序适配 iphone5 过程 经验 全记录
查看>>
绑定函数【OpenGL】关于OpenGL中Bind函数的理解
查看>>
重构机房VB.NET<机房收费系统个人重构版>你都学会了什么(之一)
查看>>
Java Annotation之应用篇 – 运行期动态解析annotation (3)
查看>>
HTTP协议/IIS 原理及ASP.NET运行机制浅析 转载
查看>>
配置邮件centos上redmine2.3.0邮件服务器报ssl错误的解决方案
查看>>
jquery获取时间差、时间格式的代码
查看>>
A pure java code of unrar. Decryption is supported.
查看>>
java hadoop file system API
查看>>
Excel中不常用的一些公式用法
查看>>
Linux下用arptables防arp攻击
查看>>