Sorry, add() === send() in my previous answer.
Just wrap all your code in a single ng-controller='RecordsController'
directive and remove it from the view:
Like:
<body ng-controller='RecordsController'>
<table align="center">
<tr>
<th>Name</th>
<th>Surname</th>
<th>Actions</th>
</tr>
<tr ng-repeat="item in serverdata">
<td>{{item.name}}</td>
<td>{{item.surname}}</td>
<td><a ng-click="delete(item.id)">Delete</a></td>
</tr>
</table>
<div ng-view></div>
</body>
The view should be without ng-controller:
<table>
<tr>
<td>Name:</td>
<td><input type="text" id="name" name="name" ng-model="name"/></td>
</tr>
<tr>
<td>Surname:</td>
<td><input type="text" id="surname" name="surname"
ng-model="surname"/></td>
</tr>
</table>
<button ng-click="send()">Add user</button>
On Monday, February 24, 2014 2:22:13 PM UTC+4, Ярослав Коновец wrote:
>
> Hi, friends!
> I want to create next template:
> <body>
> <div ng-controller='RecordsController'>
> <table align="center">
> <tr>
> <th>Name</th>
> <th>Surname</th>
> <th>Actions</th>
> </tr>
> <tr ng-repeat="item in serverdata">
> <td>{{item.name}}</td>
> <td>{{item.surname}}</td>
> <td><a ng-click="delete(item.id)">Delete</a></td>
> </tr>
> </table>
> </div>
> <div ng-view></div>
>
> </body>
>
> This is view
>
> <div ng-controller='RecordsController'>
> <table>
> <tr>
> <td>Name:</td>
> <td><input type="text" id="name" name="name" ng-model="name"/></td>
> </tr>
> <tr>
> <td>Surname:</td>
> <td><input type="text" id="surname" name="surname"
> ng-model="surname"/></td>
> </tr>
> </table>
> <button ng-click="send()">Add user</button>
> </div>
>
> And my controller:
>
> function RecordsController($scope, Data, $http) {
> $scope.serverdata = Data.AskService();
> $scope.send=function() {
> $http({
> url:'http://localhost:3000/data/add',
> method:'POST',
> data: {
> name:$scope.name,
> surname:$scope.surname,
> },
> }).success(function(data, status, headers, config) {
> $scope.serverdata=data;
> }).error(function(data, status, headers, config) {
> alert (status);
> });
>
> };
>
> $scope.delete=function(id) {
> if (confirm("Really delete record #"+id+"?"))
> $http({
> url:'http://localhost:3000/data/delete',
> method:'POST',
> data: {
> id:id,
> },
> }).success(function(data, status, headers, config) {
> $scope.serverdata=data;
> }).error(function(data, status, headers, config) {
> alert (status);
> });
> };
>
> };
>
> Help me pls with scope's understanding:when i click *Delete *button near
> the record i got normal work (scope updates automatically), but if i click
> *Add
> *button in my view, request sends successfully, but scope doesn't update.
> Help me please! Thnx!
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.