美文网首页
angularjs基础知识

angularjs基础知识

作者: zhang南方有嘉木 | 来源:发表于2017-08-01 23:15 被阅读0次

    angular的好处

    1、节省劳动力

    2、减少DOM操作

    angular的特点

    1、具备模块化

    2、双向绑定

    3、依赖注入

    正常使用angular的步骤

    1、引用文件

    2、定义angular的模块

    var app=angular.module('模块名',[]);

    ng-app="模块名"

    3、定义控制器

    app.controller('控制器名称',function($scope){

    })

    ng-controller="控制器的名称"

    指令 directive      扩展HTML的语法或者功能

    ng-app

    ng-model

    ng-init

    ng-bind

    ng-repeat

    ng-show

    ng-hide

    ng-controller

    ng-src

    ng-style

    ng-class

    ng-click

    自定义指令

    唯一操作DOM的地方

    app.directive('指令名',function () {

    return function (scope,element,attr) {

    //scope 此指令对象的作用域,可以挂属性,方法

    //element 小型jq对象

    //attr 对象身上的属性

    }

    });

    ----------------------------------

    app.directive('指令名',function () {

    return {

    link:function (scope,element,attr) {

    }

    }

    });

    ----------------------------------------

    return {

    link:function (scope,element,attr) {

    element.css('background','red');

    },

    restrict:'ECMA',

    //E  element 元素

    //C  class 样式

    //M  comment 注释

    使用的时候必须配合replace 和 template使用

    //A  attribute 属性

    template:'',

    templateUrl:'地址'

    注意:a)外部html 文件

    b) 内部script标签

    type="text/ng-template"  id

    }

    过滤器 filter

    {{a|过滤器名称:参数}}

    currency

    date

    limitTo

    lowercase

    uppercase

    number

    orderBy

    filter

    自定义过滤器

    app.filter('过滤器名称',function(){

    return function(s){

    //s 要过滤的东西

    return

    }

    })

    交互

    $http({

    url:'a.txt',

    method:'GET'

    }).then(function (res) {

    alert(res.data)

    },function (err) {

    })

    相关文章

      网友评论

          本文标题:angularjs基础知识

          本文链接:https://www.haomeiwen.com/subject/ikwslxtx.html