AngularJS-学习笔记(1)

指令

ng-app 指令定义了 AngularJS 应用程序的 根元素,在网页加载完毕时会自动引导(自动初始化)应用程序。

ng-init 指令为 AngularJS 应用程序定义了 初始值

ng-model 指令 绑定 HTML 元素 到应用程序数据。

你可以使用 .directive 函数来添加 自定义的指令。使用驼峰法来命名一个指令, runoobDirective, 但在使用它时需要以 - 分割, runoob-directive

例:<body ng-app="myApp">

< runoob-directive > < /runoob-directive >
< script >
var app = angular.module("myApp", []);
app.directive("runoobDirective", function() {
    return {
        template : "<h1>自定义指令!</h1>"
    };
});
< /script >
< /body >

你可以通过以下方式来调用指令:

  • 元素名   .directive("runoobDirective", function() {    return {        restrict : "C"     template : "<h1>自定义指令!</h1> };
  • 属性      .directive("runoobDirective", function() {    return {        restrict : "C"     template : "<h1>自定义指令!</h1> };
  • 类名      .directive("runoobDirective", function() {    return {        restrict : "C"     template : "<h1>自定义指令!</h1> };
  • 注释      .directive("runoobDirective", function() {    return {        restrict : "M"     template : "<h1>自定义指令!</h1> };
  • 注:(E 只限元素名使用,A 只限属性使用,C 只限类名使用,M 只限注释使用。restrict 默认值为 EA)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值