Angularjs contains detailed introduction and implementation examples _angularjs

Source: Internet
Author: User
Tags html form http request

Angularjs contains

In Angularjs, you can include HTML files in HTML.

Include HTML files in HTML

In HTML, the ability to include HTML files is not currently supported.

The service side contains

Most server-side scripts support the Include file feature (Ssi:server Side Includes).

With SSI, you can include HTML files in HTML and send them to the client browser.

PHP instance

<?php require ("navigation.php");?>

Client contains

There are a number of ways to include HTML files in HTML through JavaScript.

Typically we use HTTP request (AJAX) to get data from the server, and the returned data can be written to HTML elements by using InnerHTML.

Angularjs contains

With Angularjs, you can use the Ng-include directive to include HTML content:

Instance

<body>

<div class= "container" >
 <div ng-include= "' myusers_list.htm '" ></div>
 <div ng-include= "' myusers_form.htm '" ></div>
</div>

The steps are as follows:

Step 1: Create an HTML list

Myusers_list.html

 
 

Run Result:

User

Edit name Last Name
Edit {{User.fname}}} {{User.lname}}}

Step 2: Create an HTML form

Myusers_form.html

<button class= "btn btn-success ng-click=" Edituser (' new ') "> <span class=" Glyphicon glyphicon-user "></ Span> Create a new user </button>  

Run Result:

Step 3: Create the Controller

Myusers.js

Angular.module (' myApp ', []). Controller (' Userctrl ', function ($scope) {$scope. fName = '; $scope. LName = '; $scope. PASSW
1 = ';
$scope. passw2 = '; $scope. Users = [{id:1, FName: ' Hege ', lName: ' Pege '}, {id:2, fName: ' Kim ', lName: ' Pim '}, {id:3, fName: ' Sal ', lName: ' Smith '}
, {id:4, fName: ' Jack ', LName: "Jones"}, {id:5, fName: ' John ', LName: "Doe"}, {id:6, fName: ' Peter ', LName: "Pan"}];
$scope. Edit = True;
$scope. Error = FALSE; 
$scope. incomplete = false;
 $scope. Edituser = function (ID) {if (id = = ' new ') {$scope. Edit = True;
 $scope. Incomplete = true;
 $scope. fName = ';
 $scope. lName = ';
 else {$scope. Edit = FALSE;
 $scope. FName = $scope. Users[id-1].fname; 
 $scope. LName = $scope. Users[id-1].lname;

}
};
$scope. $watch (' PASSW1 ', function () {$scope. Test ();});
$scope. $watch (' passw2 ', function () {$scope. Test ();});
$scope. $watch (' FName ', function () {$scope. Test ();});

$scope. $watch (' LName ', function () {$scope. Test ();}); $scope. Test = function () {if ($scope. PASSW1!== $scope. passw2) {$scoPe.error = true;
 else {$scope. Error = FALSE;
 $scope. incomplete = false;
 if ($scope. Edit && (! $scope. fname.length | |
 ! $scope. lname.length | | ! $scope. passw1.length | |
 ! $scope. Passw2.length)) {$scope. incomplete = true;
}
}; })

Step 4: Create a home page

Myusers.html

<! DOCTYPE html>
 
 

Run Result:

The above is to angularjs contain the material collation, hope can help Angularjs programming friend.

Related Article

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.