1.angular介绍

ops/2025/3/19 18:42:28/

初級使用视频添加链接描述

angular工具

angular.module(‘名’, [依赖模块]) 模块
angular.bind(*) : 修改this指向
angualr.copy() // a = angular.copy(a, b) —a完全覆盖了b,c就是a
angular.extend(a, b) a里面集成了b属性
angular.isArray
angular.isDate
angular.isDefined 判断是否存在如果不是undefined,跟下面相反
angular.isUndefined
angular.isFunction
angular.isNumber
angular.isObject
angular.isString
angular.isElement
angular.version 版本
angular.equals 这个数组相等,nan相等
angular.forEach(values, function(value, key) {this.push(value)}, result) var result = [] values可以是数组和对象, 里面的this就是第三个参数,也就是result
angular.fromJson/toJson({}, true) // 跟JSON.stringfy那种一样,只不过变成json的时候加第二个参数true就可以格式好一些
angular.element 其实后期就可以转化成jquery这种后面使用jquery方法
angular.bootstrap 可以动态变成angular,不用初始写ng-app,需要时候在变
angular.identity/noop 其实就是返回一样的和返回undefined,平常没用

其他的就看api就行

模块的属性m1= angular.module

m1属性

  • m1.controller 控制器.写js逻辑,里面[]注入的一般是服务MVUR有$scope,$timeout(在里面使用settimeout不起作用需要使用这个timeout才行)
  • m1.run 可以弄一個全局的,不用写控制器就可以的用的
    m1.run([‘$rootScope’, function($rootScope) {
    $rootScope.name = ‘hello’
    }])
  • m1.filter 过滤器
  • m1.directive 自定义指令
  • m1.factory() 自定义服务写公共使用的
  • m1.provider() 也是自定义服务,但是跟上面factory区别,factory不可以初始化服务也就是不可以.config
  • m1.service面向对象

过滤器

自有的過濾器

  • currency: ‘¥’ biancheng变成金额
  • number: 变成数字,后面number:2 2表示小数点两位
  • lowercase/uppercase 大小写转化
  • 变成json,<pre>{{ obj |json }}<pre> 格式变成json
  • limitTo:2 截取数组或字符串2位
  • date: ** 后面可以有参数可选把毫秒格式化’223212123’|date
  • order: ‘age’ : true数组根据age进行排序, 第二个参数可以逆排序
  • filter {{name|filter :‘l’: true}}过滤数组,比如数组中匹配value值匹配到l的值,第二个参数是匹配完整的value
    也可以多個使用
    eg
javascript"><!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body ng-app="myApp" ng-controller="Aaa"><!-- 19,721,389 --><span>{{ name|number:0 }}</span> <!-- HE --><span>{{ str|limitTo: 2|uppercase}}</span><script src="./public/angular.js"></script><script>var m1 = angular.module('myApp', [])m1.controller('Aaa', ['$scope', function($scope) {$scope.name = 19721389.132143$scope.str = 'hello'}])</script>
</body>
</html>

可以使用服务形式$filter

javascript"><!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body ng-app="myApp" ng-controller="Aaa"><!-- HELLO --><span>{{ name }}</span><!-- 32221.99 --><span>{{ num }}</span><script src="./public/angular.js"></script><script>var m1 = angular.module('myApp', [])m1.controller('Aaa', ['$scope', '$filter', function($scope, $filter) {$scope.name = $filter('uppercase')('hello')$scope.num = $filter('number')(32221.9932, 2)}])</script>
</body>
</html>

自定义过滤器.模块方法兩種寫法

javascript"><!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body ng-app="myApp" ng-controller="Aaa"><!-- Hello --><span>{{ name }}</span><!-- Hello --><span>{{ lalal | firstUpper: 2 }}</span><script src="./public/angular.js"></script><script>var m1 = angular.module('myApp', [])m1.controller('Aaa', ['$scope', '$filter', function($scope, $filter) {$scope.name = $filter('firstUpper')('hello')$scope.lalal = 'hello'}])m1.filter('firstUpper', function() {return function(str, num) {console.log(num) // 2return str.charAt(0).toUpperCase() + str.substring(1)}})</script>
</body>
</html>

注意

{{}} : 表达式 对于属性来说,如果原生的egclass=“{{}}” 使用变量就需要加{},如果是ng-这种比如 ng-value="*"直接变量名就行ng-class和ng-style,如果直接表达式{}这个就行,平时原生的基本就是{{}}, ng-指令形式的就基本是变量不用加{{}} ,如果不起作用在试试别种形式

javascript"><li ng-repeat="data in dataList" class="{{$odd? 'active1': 'active2'}}">{{data}}{{$odd}}</li>
<input type="button" ng-value="text" ng-disabled="IsDisabled">
<input type="text" ng-value="text" ng-readonly="IsDisabled">
<input type="checkbox" ng-checked="IsDisabled">
<span ng-class="{active: true}" ng-style="{color: 'yellow'}">{{ text }}</span><span ng-style="ngStyle">{{ text }}</span><a ng-href="{{ngHerf}}">qubaidu</a> // 这个就需要用{{}}

http://www.ppmy.cn/ops/167084.html

相关文章

涨薪技术|Kubernetes(k8s)之Pod生命周期(下)

上次推文我们学习了Pod生命周期&#xff08;上&#xff09;知识&#xff1a;相位、创建与终止、初始化容器&#xff0c;今天继续分享完余下的3个知识&#xff1a;钩子函数、容器探测、重启策略。 01钩子函数 钩子函数能够感知自身生命周期中的事件&#xff0c;并在相应的时刻…

【机器学习】基于conda虚拟环境的gcc、g++版本升级

最近在学习大模型部署&#xff0c;需要安装flash-attn&#xff0c;在编译时报错 c: error: unrecognized command line option ‘-stdc17’centos7.9默认gcc最高版本为4.8.5 (base) [rootxx ~]# cat /proc/version Linux version 3.10.0-1160.el7.x86_64 (mockbuildkbuilder.…

排错 -- FISCO BCOS区块链网络 -- 3. 编译智能合约

文章为FISCO BCOS2.0搭建区块链平台中发现的问题与总结&#xff0c;出错原因不唯一 &#xff0c;解决办法不唯一 目前社区缺少完整&#xff0c;稳定的搭建平台和教程 &#xff0c;欢迎各位及时补充&#xff0c;如有错误请及时评论纠正&#xff01; 感谢各位搜索到这里&#…

【STM32】从新建一个工程开始:STM32 新建工程的详细步骤

STM32 开发通常使用 Keil MDK、STM32CubeMX、IAR 等工具来创建和管理工程。此处是 使用 Keil MDK5 STM32CubeMX 创建 STM32 工程的详细步骤。 新建的标准库工程文件已上传至资源中&#xff0c;下载后即可直接使用。 标准库新建 STM32 工程的基本目录结构&#xff1a;STD_STM…

Vue3中正确解析RefImpl对象

在 Vue 3 中&#xff0c;当你看到 RefImpl 对象时&#xff0c;说明这是一个通过 ref() 创建的响应式引用。要获取它的实际值&#xff0c;直接访问 .value 属性即可。以下是具体方法&#xff1a; 直接获取值&#xff08;标准方式&#xff09; javascript 复制 console.log(&q…

【蓝桥杯】每天一题,理解逻辑(4/90)【Leetcode 二进制求和】

题目描述 我们解析一下题目 我们可以理解到两个主要信息 给的是二进制的字符串返回他们的和 我们知道&#xff0c;十进制的加减法需要进位&#xff0c;例如&#xff1a;9716是因为91之后进了一位&#xff0c;二进制也是如此&#xff0c;只不过十进制是逢10进1&#xff0c;二…

Go string 字符串底层逻辑

在 Go 语言中&#xff0c;string 类型的底层结构是一个结构体&#xff0c;包含两个字段&#xff1a;一个指向字节数组的指针和该字节数组的长度。以下是其在 Go 源码中的大致定义&#xff1a;type stringStruct struct {str unsafe.Pointerlen int } str&#xff1a;这是一个指…

Git的基本指令

一、回滚 1.git init 在项目文件夹中打开bash生成一个.git的子目录&#xff0c;产生一个仓库 2.git status 查看当前目录下的所有文件的状态 3.git add . 将该目录下的所有文件提交到暂存区 4.git add 文件名 将该目录下的指定文件提交到暂存区 5.git commit -m 备注信…