как сообщить, что область видимости обновлена в angularjs?

0

Вот мой 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>

Вопрос: - У меня есть два разных контроллера. Как я могу автоматически обновлять свой клиентский Ctrl сразу после обновления контроллера sign_up?

вот мой код javascript: -

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;
            });
        }
    })
Теги:
angularjs-scope

1 ответ

0

Вы можете использовать часы, трансляцию или излучать.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню