如何使用AngularJs在html中定义两个模型

How can I define two model in html with AngularJs

本文关键字:两个 模型 定义 AngularJs 何使用 html      更新时间:2023-09-26

我是AngularJs 的新手

如果我想在html 中定义两个模型

我该如何定义它?

我已经试过很多次了

请帮助

<body ng-app="experiment">
<div  ng-controller="functionCrtl" id="staff"> 
<div ng-modle="data1.data">
   <ng-view></ng-view>  
</div>

<div ng-app="experiment_left">
<div ng-controller="accordtionCrtl">
    <div ng-model="accordtion.accordtion">
      <ng-view></ng-view>
    </div>
</div>

experiment.config (function($routeProvider) {
 $routeProvider.when("/",{
templateUrl : "function1.html",
controller: 'functionCrtl'});

我想动态加载两页,我该怎么办?

但要回答您的问题,请阅读以下内容http://docs.angularjs.org/api/ng.directive:input.

控制器:

 angular.module('myApp').controller('CreateUserCtrl', function ($scope) {
         $scope.firstname = 'John';
         $scope.surname = 'Doe';
});

HTML

<form ng-controller="CreateUserCtrl">
     <input ng-model="firstname " type="text" placeholder="firstname">
     <input ng-model="surname" type="text" placeholder="surname">
</form>