0

Here is my html:-

<div ng-app="myApp">
<!-- this controller will be in different page -->
    <table ng-controller="customersCtrl">
        <tr ng-repeat="x in names">
            <td><a ng-href="#/edit/{{x.id}}">{{ x.name }}</a></td>
            <td>{{ x.description }}</td>
        </tr>
    </table>
<!-- this controller will be in different page -->
    <div id="login" ng-controller='sign_up'>
        <input type="text" size="40" ng-model="name"><br>
        <input type="text" size="40" ng-model="description"><br>
        <button ng-click="check_credentials()">Login</button><br>
        <span id="message"></span>
    </div>
</div>

Question:- I have two different controller, How can I automatically update my customerCtrl as soon as sign_up controller update?

here is my javascript code:-

var app = angular.module('myApp', [])
    .controller('customersCtrl', function($scope, $http) {
        $http.get("exp.php").success(function(response) {
            $scope.names = response;
        })
    })
    .controller('sign_up', function ($scope, $http) {
        $scope.check_credentials = function () {
            var request = $http({
                method: "post",
                url: window.location.href + "save.php",
                data: {
                    name: $scope.name,
                    description: $scope.description
                },
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
            });
            request.success(function (data) {
                document.getElementById("message").textContent = "You have login successfully with name " + data;
            });
        }
    })
Marmik Desai
  • 104
  • 11
  • maybe duplicate with this one http://stackoverflow.com/questions/28337048/communicating-between-controllers-in-angularjs/28337130#28337130 – Rebornix Jul 07 '15 at 07:13
  • @Tushar do you have any example for this? – Marmik Desai Jul 07 '15 at 07:19
  • Here's a good way of handling this: http://stackoverflow.com/questions/18856153/how-can-i-pass-some-data-from-one-controller-to-another-peer-controller – von v. Jul 07 '15 at 07:21

1 Answers1

0

You can use watch, broadcast or emit.

Johnny Ha
  • 633
  • 5
  • 21