How to get built-in services to obtain local information in Angular
We used angular to set a timer before. Today we will do some exercises based on the timer.
Use the built-in service to obtain the following information:
1. Get the screen height
2. Get the screen width
3.Get the pagetitle
4.GetURLProtocol
5.GetURLHost
6. Get the port number
7.Get the hash part of URL
8.Get the access address, that is, URLAddress
##Other requirements:
1. The height and width are displayed 2 seconds after opening the page
2.title, protocol, host will be displayed 3 seconds after opening the page
3. Port number, url address will be displayed 5 seconds after opening the page After that, a prompt box will pop up asking whether to display it. If you click yes, it will be displayed. Otherwise, it will not be displayed.
Source code:
##<!DOCTYPE html><html><head>
<meta charset="UTF-8">
<script type="text/javascript" src="angular-1.3.0.js"></script>
<title>day12日考</title></head><body ng-app="myApp"><p ng-controller="myCtrl">
<p>屏幕有效的宽度(单位:像素):{{ width }}</p>
<p>屏幕有效的高度(单位:像素):{{ height }}</p>
<p>页面title:{{ title }}</p>
<p>URL主机:{{ host }}</p>
<p>URL协议:{{ protocol }}</p>
<p>端口:{{ port }}</p>
<p>URL的hash部分:{{ hash }}</p>
<p>URL地址:{{ href }}</p></p><script>
var nowtime = function () { return new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString();
}; var app = angular.module("myApp", []); app.controller("myCtrl", function ($scope, $interval, $timeout) {
$interval(function () {
$scope.width = screen.availWidth;
$scope.height = screen.availHeight;
}, 2000);
$timeout(function () {
$scope.title = document.title;
$scope.host = location.host;
$scope.protocol = location.protocol;
}, 3000);
$timeout(function () { var msg = "是否显示?"; if (confirm(msg)==true){
$scope.port = window.location.port;
$scope.hash = location.hash;
$scope.href = window.location.href;
}else{ alert("你选择了不展示");
}
}, 5000);
});</script></body></html>
The above is the detailed content of How to get built-in services to obtain local information in Angular. For more information, please follow other related articles on the PHP Chinese website!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

A file extension in Python is a suffix appended to the end of a file name to indicate the format or type of the file. It usually consists of three or four characters, a file name followed by a period, such as ".txt" or ".py". Operating systems and programs use file extensions to determine what type of file it is and how it should be processed. Recognized as a plain text file. File extensions in Python are crucial when reading or writing files because it establishes the file format and the best way to read and write data. For example, the ".csv" file extension is the extension used when reading CSV files, and the csv module is used to process the files. Algorithm for obtaining file extension in Python. Manipulate file name string in Python.

Angular.js is a freely accessible JavaScript platform for creating dynamic applications. It allows you to express various aspects of your application quickly and clearly by extending the syntax of HTML as a template language. Angular.js provides a range of tools to help you write, update and test your code. Additionally, it provides many features such as routing and form management. This guide will discuss how to install Angular on Ubuntu24. First, you need to install Node.js. Node.js is a JavaScript running environment based on the ChromeV8 engine that allows you to run JavaScript code on the server side. To be in Ub

Google Authenticator is a tool used to protect the security of user accounts, and its key is important information used to generate dynamic verification codes. If you forget the key of Google Authenticator and can only verify it through the security code, then the editor of this website will bring you a detailed introduction on where to get the Google security code. I hope it can help you. If you want to know more Users please continue reading below! First open the phone settings and enter the settings page. Scroll down the page and find Google. Go to the Google page and click on Google Account. Enter the account page and click View under the verification code. Enter your password or use your fingerprint to verify your identity. Obtain a Google security code and use the security code to verify your Google identity.

Remote desktop connection has brought convenience to many users' daily lives. Some people want to use commands to connect remotely, which is more convenient to operate. So how to connect? Remote Desktop Connection Service can help you solve this problem by using a command to open it. How to set up the remote desktop connection command: Method 1. Connect remotely by running the command 1. Press "Win+R" to open "Run" and enter mstsc2, then click "Show Options" 3. Enter the IP address and click "Connect". 4. It will show that it is connecting. Method 2: Connect remotely through the command prompt 1. Press "Win+R" to open "Run" and enter cmd2. In the "Command Prompt" enter mstsc/v:192.168.1.250/console

What is the correct way to restart a service in Linux? When using a Linux system, we often encounter situations where we need to restart a certain service, but sometimes we may encounter some problems when restarting the service, such as the service not actually stopping or starting. Therefore, it is very important to master the correct way to restart services. In Linux, you can usually use the systemctl command to manage system services. The systemctl command is part of the systemd system manager

The default display behavior for components in the Angular framework is not for block-level elements. This design choice promotes encapsulation of component styles and encourages developers to consciously define how each component is displayed. By explicitly setting the CSS property display, the display of Angular components can be fully controlled to achieve the desired layout and responsiveness.

Authentication is one of the most important parts of any web application. This tutorial discusses token-based authentication systems and how they differ from traditional login systems. By the end of this tutorial, you will see a fully working demo written in Angular and Node.js. Traditional Authentication Systems Before moving on to token-based authentication systems, let’s take a look at traditional authentication systems. The user provides their username and password in the login form and clicks Login. After making the request, authenticate the user on the backend by querying the database. If the request is valid, a session is created using the user information obtained from the database, and the session information is returned in the response header so that the session ID is stored in the browser. Provides access to applications subject to

If the "Get the latest updates as soon as they become available" option is missing or grayed out, you may be running a Developer Channel Windows 11 build, and this is normal. For others, issues arise after installing the KB5026446 (22621.1778) update. Here's what you can do to get back the "Get the latest updates as soon as they become available" option. How do I get the "Get the latest updates as soon as they're available" option back? Before starting any of the solutions below, make sure to check for the latest Windows 11 updates and install them. 1. Use ViVeTool to go to the Microsoft Update Catalog page and look for the KB5026446 update. Download and reinstall the update on your PC
