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