Angular + Node: Method for generating random numbers. angularnode

Source: Internet
Author: User

Angular + Node: Method for generating random numbers. angularnode

This article describes how Angular + Node generates random numbers. We will share this with you for your reference. The details are as follows:

I used to write a PHP program to generate a random number, and then get it through jquey ajax. Then jQuery is used to change the random number of the text.

Now we use Angular and Node to rewrite it.

Angular has the advantage of two-way binding. In this way, you can directly set variables without resetting them.

I am not very familiar with the advantages of Node. I can use the count example to illustrate the differences between Node and PHP.

Of course, the biggest benefit is that the front and back ends can be written in JavaScript, so that the Javascript level will be greatly improved!

Node

App. js

var express = require('express');var app = express();var count = 0;app.get('/', function (req, res) { res.header('Access-Control-Allow-Origin', '*'); var x = Math.floor(Math.random() * 1e6); res.send(String(x)); console.log(count++);});app.listen(3000, function () { console.log('Example app listening on port 3000!');});res.header('Access-Control-Allow-Origin', '*');

This involves cross-domain issues. In addition, this sentence cannot be accessed locally. You must use the hybrid APP later.
Then, a random number is generated. The key is the count variable. Each time a random number is accessed during subsequent execution, it is different. This indicates that Node is resident memory and does not want PHP to be loaded.

Angular

<! DOCTYPE html> 

There are some concepts:

Module

Ng-app module, which is modular at present

Controller

Ng-controller is an object
The object contains members and is accessed using $ scope.

PS: here we will provide you with two online tools with similar functions for your reference:

Online random number/string generation tool:
Http://tools.jb51.net/aideddesign/suijishu

High-strength Password generator:
Http://tools.jb51.net/password/CreateStrongPassword

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.