angular 中从一个模板到另一个模板的访问值

access value from one template to other in angular

如何使用从一个模板1到模板2的模型值?

这是我的代码:- index.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Example - example-example84-production</title>

  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular-animate.js"></script>
  <script src="script.js"></script>



</head>
<body ng-app="includeExample">
  <div ng-controller="ExampleController">
     <div ng-include="'template1.html'"></div>
    <div ng-include="'template2.html'"></div>

</div>
</body>
</html>

template1.html

Content of template1.html
<br/>
<input ng-model="x"/>

template2.html

Content of template2.html
<br/>
x={{x}}

Plukr- http://plnkr.co/edit/HF1KxLzGbmP4S7gVc5fQ?p=preview

只需使用 "controller as" 语法:

<body ng-app="includeExample">
  <div ng-controller="ExampleController as ex">
     <div ng-include="'template1.html'"></div>
    <div ng-include="'template2.html'"></div>

</div>

在您的模板中:

x={{ex.x}}


<input ng-model="ex.x"/>

笨蛋:

http://plnkr.co/edit/FVkSj2vs8WDAt1eifBpF?p=preview