作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作一张名片订单,其中包含一个添加另一张名片的按钮。我希望该按钮创建另一个名片表单,并将表单中的所有数据与另一个 View 的 Controller 共享。
我有两个模板连接到各自的 Controller 。
代码示例:
order.js
.factory('Cards', function () {
var Cards = []
return Cards
})
.controller('TestCtrl', function ($scope, Cards) {
$scope.person0={name: '', email:'', description:''}
$scope.person1={name: '', email:'', description:''}
if (Cards.length < 2) {
Cards.push($scope.person0);
Cards.push($scope.person1);
}
}
order.html
<md-toolbar layout='column' layout-align='center' ng-repeat="card in Cards">
<md-button layout-margin layout-padding flex='100' class='md-raised md-primary'>
<h1>{{ card.name }}</h1>
<h1>{{ card.email }}</h1>
<h1>{{ card.description }}</h1>
</md-button>
<div layout='column' layout-align='center center' >
<input type="text" style="color:black;" flex='' ng-model="card.name">
<input type="text" style="color:black;" flex='' ng-model="card.email">
<input type="text" style="color:black;" flex='' ng-model="card.description">
</div>
</md-toolbar>
about.js
.controller('AboutCtrl', function ($scope, Cards) {
$scope.person0=Cards[0];
$scope.person1=Cards[1];
});
about.html
<div ng-repeat="card in Cards">
<md-toolbar layout='column' layout-align='center'>
<md-button layout-margin layout-padding flex='100' class='md-raised md-primary'>
<h1>{{card.name}}</h1>
<h1>{{card.email}}</h1>
<h1>{{card.description}}</h1>
</md-button>
</md-toolbar>
<md-content>
</md-content>
</div>
我希望order.html中的表单数据显示在confirm.html上
两个 View 都会记录 Cards 集合,但不会显示 ng-repeat 模板。
最佳答案
放慢脚步,仔细观察。
在 about.html
中,您似乎想要循环浏览卡片。
<div ng-repeat="card in Cards">
但在 about.js
中,每个单独的卡片都分配给范围。
$scope.person0=Cards[0]; // no reference in template
要解决此问题,请将卡片放在 about.js
范围内。
$scope.Cards = Cards
关于javascript - 跨 Controller 共享 ng-repeat 表单字段的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29806659/
我尝试通过正则表达式将文本中的单引号更改为双引号。 (单字)示例:我走了。 You gona fly to planet 'Ziqtos' => 我需要在 I'm 中保留单引号,并在 You gona
我正在构建一个 API,其中大部分将包含 JSON 和 HTML 内容。但是一些非常具体的端点只呈现 true 或 false,并且还在 POST 中接受 true 或 false。这是请求或响应的整
我是一名优秀的程序员,十分优秀!