javascript - Sharing data of a ng-repeat form field across controllers -
i’m making order form business card button add business card. want button create business card form , data forms shared controller of view.
i have 2 templates connected respective controllers.
- order.html, order.js
- confirm.html, confirm.js
code samples:
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>
i want form data order.html displayed on confirm.html
the cards collection gets logged both views ng-repeat templates not displayed.
slow down , take closer look.
in about.html
looks want loop through cards.
<div ng-repeat="card in cards">
but in about.js
each individual card assigned scope.
$scope.person0=cards[0]; // no reference in template
to fix this, put cards on about.js
scope.
$scope.cards = cards
Comments
Post a Comment