This article mainly introduces Angular's implementation of search box and price upper and lower limit functions in detail. It has certain reference value. Interested friends can refer to it.
If you have nothing to do, write one Simple angular search box.
1. Requirements:
Use the AngularJS framework to implement the mobile product search function. Question requirements:
1) Search for materials by yourself and convert the mobile phone to the original data format. The product data is enriched to at least 10 or more
2) Design the page by yourself, which needs to include the "search condition part" and the "mobile phone information display part"
3) When changing any search conditions, the search results need to be displayed in real time in "
4 in "Display Part") Specific requirements for search conditions:
Search box (match operating system, product name, manufacturer for fuzzy query)
Price range (start price ~ end price)
2. Requirements analysis:
First, we need to render the product onto the page.
Secondly, when we enter the search box text, products that match the search box text are dynamically displayed.
Among them, dynamic means that every time we enter a character, the product will be filtered.
Finally, the same principle applies to the upper and lower limits of price.
So, in this way, it is most convenient for us to use angular. Because angular supports bidirectional data very well.
3. Actual code:
1) HTML code:
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>AngularJS Page Useing Bootstrap Framework</title> <link rel="stylesheet" href=""> <script src="./lib/angular/angular-v1.6.6.js"></script> </head> <body ng-app="searchApp"> <p ng-controller="dataCtrl"> <input type="text" name="搜索框" ng-model="content" placeholder="请输入要搜索的物品"> <input type="text" name="价格上限" ng-model="top" placeholder="价格上限"> <input type="text" name="价格下限" ng-model="bottom" placeholder="价格下限"> <p> <ul> <li ng-repeat="p in datas"> {{p.name}} </li> </ul> </p> </p> </body> </html>
2) JS code:
let httpApp = angular.module( 'searchApp', [] ); httpApp.controller( 'dataCtrl', [ "$scope", "$http", function( $scope, $http ){ let http = $http.get( "conf.json" ); //模拟从后端获取的json数据。 $scope.content = ''; $scope.$watch("content + top + bottom",function(){ http.then( // success callback function success( response ){ $scope.datas = response.data; //进行价格筛选。 $scope.datas=$scope.datas.filter(function( x,index ){ if($scope.top===undefined&&$scope.bottom===undefined) { return 1; } else if($scope.top===undefined){ return x.price>=$scope.bottom } else if($scope.bottom===undefined){ return x.price<=$scope.top; } else{ return x.price>=$scope.bottom&&x.price<=$scope.top; } }); //进行搜索内容筛选。 $scope.datas=$scope.datas.filter(function( x,index ){ system=x.system.indexOf($scope.content)+1; name = x.name.indexOf($scope.content)+1; producer=x.producer.indexOf($scope.content)+1; if(system+name+producer>=1){ return 1; } else{ return 0; } }) }, // error callback function error( response ){ console.log( response ); } ); }); } ] );
PS: For I'm lazy, I didn't write a very nice style. You can add it yourself if you need.
3) conf.json code:
[ { "system": "ios", "name": "Apple iPhone 6s 16GB 玫瑰金色", "price": 4698, "producer": "Apple", "pic": "01.jpg" }, { "system": "MIUI", "name": "小米手机4S 全网通版 2GB内存 16GB 白色", "price": 1499, "producer": "小米", "pic": "02.jpg" }, { "system": "Android", "name": "魅蓝note3 (16GB) 银色 全网通公开版 双卡双待", "price": 1099, "producer": "魅族科技", "pic": "03.jpg" }, { "system": "ios", "name": "Apple iPhone 6s Plus 64GB 银色 移动联通电信4G手机", "price": 6587, "producer": "Apple", "pic": "04.jpg" }, { "system": "ios", "name": "Apple iPhone 6s Plus 64GB 银色 移动联通电信4G手机", "price": 6578, "producer": "Apple", "pic": "04.jpg" }, { "system": "ios", "name": "Apple iPhone 6s Plus 64GB 银色 移动联通电信4G手机", "price": 6788, "producer": "Apple", "pic": "04.jpg" }, { "system": "ios", "name": "Apple iPhone 6s Plus 64GB 银色 移动联通电信4G手机", "price": 6878, "producer": "Apple", "pic": "04.jpg" }, { "system": "ios", "name": "Apple iPhone 6s Plus 64GB 银色 移动联通电信4G手机", "price": 6528, "producer": "Apple", "pic": "04.jpg" }, { "system": "ios", "name": "Apple iPhone 6s Plus 64GB 银色 移动联通电信4G手机", "price": 6988, "producer": "Apple", "pic": "04.jpg" }, { "system": "ios", "name": "Apple iPhone 6s Plus 64GB 银色 移动联通电信4G手机", "price": 6388, "producer": "Apple", "pic": "04.jpg" }, { "system": "ios", "name": "Apple iPhone 6s Plus 64GB 银色 移动联通电信4G手机", "price": 6378, "producer": "Apple", "pic": "04.jpg" }, { "system": "ios", "name": "Apple iPhone 6s Plus 64GB 银色 移动联通电信4G手机", "price": 6738, "producer": "Apple", "pic": "04.jpg" }, { "system": "ios", "name": "Apple iPhone 6s Plus 64GB 银色 移动联通电信4G手机", "price": 6568, "producer": "Apple", "pic": "04.jpg" }, { "system": "ios", "name": "Apple iPhone 6s Plus 64GB 银色 移动联通电信4G手机", "price": 6558, "producer": "Apple", "pic": "04.jpg" }, { "system": "ios", "name": "Apple iPhone 6s Plus 64GB 银色 移动联通电信4G手机", "price": 6738, "producer": "Apple", "pic": "04.jpg" }, { "system": "ios", "name": "Apple iPhone 6s Plus 64GB 银色 移动联通电信4G手机", "price": 6428, "producer": "Apple", "pic": "04.jpg" }, { "system": "ios", "name": "Apple iPhone 6s Plus 64GB 银色 移动联通电信4G手机", "price": 652488, "producer": "Apple", "pic": "04.jpg" }, { "system": "ios", "name": "Apple iPhone 6s Plus 64GB 银色 移动联通电信4G手机", "price": 654588, "producer": "Apple", "pic": "04.jpg" }, { "system": "ios", "name": "Apple iPhone 6s Plus 64GB 银色 移动联通电信4G手机", "price": 6545645688, "producer": "Apple", "pic": "04.jpg" } ]
PS: The json data transmitted by the server is simulated through the object. In addition, pictures can be added and implemented by yourself.
4. Final question:
Of course, the code I uploaded left a hole. How to cancel the restriction of the corresponding price range after entering the price and clearing it.
Finally, you can think about how the search method can be optimized as an expansion.
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Detailed introduction to the nextTick method in Vue
What are the usages of slots in Vue components (details Tutorial)
vue project structure (detailed tutorial)
How to implement the email prompt completion function in JS
How to implement parabolic motion through JS (detailed tutorial)
How to use session and cookie methods in express (detailed tutorial)
How to implement the Bezier curve algorithm using JavaScript (detailed tutorial)
The above is the detailed content of How to implement a search box using Angular. For more information, please follow other related articles on the PHP Chinese website!

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

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.


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

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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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

Dreamweaver Mac version
Visual web development tools
