


How much do you know about the basic introduction to angularjs? Here is a detailed introduction to angularjs
This article introduces a brief intermediate article about angularjs, introduces single-page web applications, three template methods,$scope, Scope, Traversal, Other instructions, Request datajqLite, $watch, $apply. Next let us read this article together
Characteristics of single-page applications: The entire website consists of one page, the public part is only loaded once, and Ajax partial refresh is used to achieve the purpose of page switching. When the page jumps to a white screen, the anchor point and the page correspond to the single-page web application.
Scenario: Single-page applications are not friendly to search engines and are not suitable for public display websites. Website back-end management systems, Office OA, hybrid apps and other applications that do not need to be searched by search engines
<script src="node_modules/angular/angular.min.js"></script> <script src="node_modules/angular-route/angular-route.min.js"></script> <body ng-app="myApp"> <a href="#!/index">首页</a> <a href="#!/list">列表页</a> <div ng-view></div> </body> <script> var app=angular.module('myApp',['ngRoute']) app.config(function($routeProvider){ $routeProvider .when('/index',{ templateUrl:'./tpl/index.html', controller:'indexCtrl' }) .when('/list',{ templateUrl:'./tpl/list.html', controller:'listCtrl' }) .otherwise('/index') }); app.controller('indexCtrl',function($scope){ $scope.msg="我是首页msg" }) app.controller('listCtrl',function($scope){ $scope.msg="我是列表页msg" }) </script>
Three template methods
<script> templateUrl:'./tpl/index.html'//localhost template:'<div>我是首页</div>'//file|localhosst template:'indexTpl'//file|localhosst</script>
$scope
There are many parameters that can be passed, there is no need to write them out one by one
You cannot rely on passing parameters in angularjs The order is the name
If the formal parameter name changes, angularjs will not know what to do
Solution: write an array as the second parameter, and put the callback function in the array
During compression, the string will not be compressed, so the string is passed in the array to determine the order of parameters
<script> angular.module("myApp",[]).controller("demoCtrl",["$scope","$timeout","$http","$location",function(a,b,c,d){ a.msg="我是msg" }]) </script>
Scope
Function Domain proximity principle
The area controlled by the controller in angularjs is a local scope,
That is, $scope represents the local scope
$rootScope represents the global scope Domain
Variables are first searched along $scope. If not found, search globally.
You can mount public attribute methods
Traverse
ng-repeat="Current item in data during loop" loops data and generates current DOM element
<ul> <li ng-repeat="item in arr">{{item}}</li> </ul>
Traverse array objects, can be nested, with ng-repeat Tags of ng-repeat can also be nested
-
{{person.name}}{{person.age}}
{{item}}
数组项重复,会报错
<ul> <li ng-repeat="item in arr track by $index">{{item}}</li> </ul>
其他指令
ng-class="{'类名1':布尔值,'类名2':布尔值}"专门用来添加或者删除类名,接收的值是一个对象,布尔值为真,添加类名,布尔值为假,删除类名
复选框,ng-model用来获取复选框的值,是一个布尔值
ng-bind="数据",将msg放到属性中进行加载,避免出现闪烁效果
ng-bind-template="{{数据1}} {{数据2}}"
ng-non-bindable直接得到插值表达式中的内容,只要与属性相关,都不执行
ng-show="布尔值",控制元素的显示和隐藏
ng-hide="布尔值",控制元素的显示和隐藏
ng-if="布尔值",控制元素的显示和隐藏 true 显示 false 隐藏
ng-switch&ng-switch-when用法和switch-case类似
事件指令
onclick => ng-click
onmouseenter => ng-mouseenter
onchange => ng-change
ng-dblclick 双击事件
ng-src没有src就不会解析就不会报错,直到angularjs加载完成,解析ng-src之后再生成src
ng-href同上
ng-options用来循环下拉列表,不能单独使用,需要配合ng-model一起使用
请求数据
要请求数据需要先引入js文件
引入的js文件作为依赖文件,控制器中必须写入$http
$http-->请求的地址,相当于jQuery中的ajax
method-->type请求的方式
params-->data只用于get传参
data可以用于post传参
$http点then后面是两个回调函数
第一个回调函数是成功回调
第二个回调函数是失败回调
res是形参,表示请求回来的数据
<script src="node_modules/angular/angular.js"></script> <script src="node_modules/angular-sanitize.min.js"></script> <script> angular.module('myApp',['ngSanitize']) .controller('demoCtrl',['$scope','$http',function($scope,$http){ $http({ url:'./test.json', method:'post',//请求方式 params:{//get传参 a:1, b:2 }, data:{ c:3, d:4 } }).then(function(res){ //成功回调 console.log(res) },function(){ //失败回调 }) //另外一种写法 $http.get('./test.json',{params:{a:1,b:2}}).then(function(res){ //get方式传参 console.log(res) }) $http.post('./test.json',{c:3,d:4}.then(function(res){ //post方式传参 console.log(res) }) }]) </script>
jqLite
为了方便DOM操作,angularjs提供了一个jQuery精简版,叫做jqLite
$(原生的JS对象)将原生JS对象转换成jQuery对象,目的是为了使用jQuery对象下面提供的方法
angularjs.element(原生JS对象)将原生JS对象转换成jqLite对象,目的是为了使用jqLite对象下面提供的方法
这里angularjs.element相当于jQuery中的$
jqLite中方法的使用和jQuery高度相似
$watch
$watch用来监控数据的变化
第一个参数是要监控的数据,第二个参数是回调函数
回调函数中第一个参数newValue是用户输入的最新内容,第二个参数oldValue是上一次用户输入的内容
页面一上来的时候,回调函数会先执行一次
<script> $scope.$watch('val',function(newValue,oldValue){ if(newValue.length>10){ $scope.tips="大于10"; }else{ $scope.tips="小于10" } }) </script>
$apply
当通过原生JS将angularjs中的数据做了改变以后,angularjs不知道,所以需要调用$apply()方法通知angularjs更新html页面
以上就本篇关于angularjs简历的中级篇文章了,下一篇终极的在后面,大家期待吧,想学更多关于angularjs的相关知识就到PHP中文网angularjs参考手册栏目中学习。
The above is the detailed content of How much do you know about the basic introduction to angularjs? Here is a detailed introduction to angularjs. For more information, please follow other related articles on the PHP Chinese website!

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6
Visual web development tools