Latest web development tutorials

AngularJS contiene

In AngularJS, è possibile includere i file HTML in HTML.


Esso contiene il file HTML in HTML

In HTML, questo non è supportato dal file HTML che contiene la funzione.


Servizio Side Includes

La maggior parte delle funzioni di supporto di scripting lato server includono il file (SSI: Server Side Includes).

Utilizzando SSI, si può essere incluso nel file HTML nel codice HTML inviato al browser client.

Esempi PHP

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

client contiene

Ci sono molti modi di JavaScript possono contenere file HTML in HTML.

Di solito si usa richieste HTTP (AJAX) per ottenere i dati dal server, siamo in grado di scrivere i dati restituiti utilizzando innerHTML per l'elemento HTML.


AngularJS contiene

Utilizzare AngularJS, è possibile utilizzare ng-direttiva include per includere contenuto HTML:

Esempi

<Body>

<Div class = "contenitore">
<Div ng-include = " ' myUsers_List.htm'"> </ div>
<Div ng-include = " ' myUsers_Form.htm'"> </ div>
</ Div>

</ Corpo>

Procedere come segue:


Passo 1: Creare elenchi HTML

myUsers_List.html

<H3> Utenti </ h3>

<Tabella class = "tavolo- tabella a strisce">
<Thead> <tr>
<Th> Modifica </ th>
<Th> Nome </ th >
<Th> Cognome </ th >
</ Tr> </ thead>
<TBODY> <tr NG-repeat = "utente in utenti">
<Td>
<Classe Button = "btn" ng -Click = "editUser (user.id)">
<Span class = "glyphicon glyphicon- matita"> </ span> & nbsp; & nbsp; Modifica
</ Button>
</ Td>
<Td> {{user.fName}} </ td>
<Td> {{user.lName}} </ td>
</ Tr> </ tbody>
</ Table>

Prova »

Fase 2: Creare un form HTML

myUsers_Form.html

<Classe Button = "btn btn- successo" ng-click = "editUser ( 'nuovo')">
<Span class = "glyphicon glyphicon- utente"> </ span> Crea nuovo utente
</ Button>
<Hr>

<H3 ng-show = "Modifica "> Crea un nuovo utente: </ h3>
<H3 ng-nascondere = "Modifica "> Modifica utente: </ h3>

<Classe Form = "form-orizzontale ">
<Div class = "forma-gruppo ">
<Classe Label = "col-sm -2 controllo-label"> Nome: </ label>
<Div class = "col-sm -10">
<Input type = "text" ng -model = "fName" ng-disabled = "! Modifica" segnaposto = "Nome">
</ Div>
</ Div>
<Div class = "forma-gruppo ">
<Classe Label = "col-sm -2 controllo-label"> Nome: </ label>
<Div class = "col-sm -10">
<Input type = "text" ng -model = "lname" ng-disabled = "! Modifica" segnaposto = "Cognome">
</ Div>
</ Div>
<Div class = "forma-gruppo ">
<Classe Label = "col-sm -2 controllo-label"> Password: </ label>
<Div class = "col-sm -10">
<Input type = "password" ng -model = "passw1" segnaposto = "password">
</ Div>
</ Div>
<Div class = "forma-gruppo ">
<Classe Label = "col-sm -2 controllo-label"> Ripeti: </ label>
<Div class = "col-sm -10">
<Input type = "password" ng -model = "passw2" segnaposto = "Ripeti password">
</ Div>
</ Div>
</ Form>

<Hr>
<Classe Button = "btn btn- successo" ng-disabled = "Errore || incompleta">
<Span class = "glyphicon glyphicon- salvare"> </ span> Salva modifiche
</ Button>

Prova »

Passaggio 3: Creare controller

myUsers.js

angular.module( 'myApp' , []).controller( 'userCtrl' , function ($scope) {
$scope.fName = '' ;
$scope.lName = '' ;
$scope.passw1 = '' ;
$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 ;
  }
};
})

Fase 4: Creare una Homepage

myUsers.html

<! DOCTYPE html>
<HTML>
<Link rel = "stylesheet" href = "http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<Script src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> </ script>

<Corpo ng-app = "myApp " ng-controllore = "userCtrl">

<Div class = "contenitore">
<Div ng-include = " ' myUsers_List.htm'"> </ div>
<Div ng-include = " ' myUsers_Form.htm'"> </ div>
</ Div>

<Script src = "myUsers.js"> </ script>

</ Corpo>

</ Html>

Prova »