Perhaps raw deviation is an error when creating a shape with angular

I created this simple web application to put data in a firebase database. The problem is that I get an error when opening a webpage in my browser. This is the error I get

Possibly unhandled rejection: {} angular.js:14324

Also, when I press the sumbit button for the first time without data in the fields, it shows the same error as above. Then, when I click the button again, it sends empty fields to the database. I think angular detects that these fields are empty. Am I missing something? Putting text in fields works fine, and it is also sent to the database. It is simply with blank fields that their problems.

var app = angular.module("sampleApp", ["firebase"]);
app.controller("SampleCtrl", function($scope, $firebaseArray) {
    var ref = firebase.database().ref().child("messages");
    $scope.loading = true;
    $firebaseArray(ref).$loaded().then(function(){
        $scope.loading = false;
        document.getElementById('loader').style.display = 'none';
    });
    $scope.messages = $firebaseArray(ref);
    $scope.addMessage = function() {
        $scope.messages.$add({
            name: $scope.name,
            company: $scope.company,
            reason: $scope.reason,
            wayofcontact: $scope.wayofcontact,
        });
        $scope.name = '';
        $scope.company = '';
        $scope.reason = '';
        $scope.wayofcontact = '';
        document.getElementById("name").focus();
    };
});
<!DOCTYPE html>
<html ng-app="sampleApp">
<head>
    <meta charset="utf-8">
    <title>AngularJS Tutorial</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous">
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <style>
    [ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
        display: none !important;
    }
    ul {
        list-style-type: none;
    }
    </style>
</head>
<body ng-controller="SampleCtrl" ng-cloak >
    <div class="container" ng-view>
        <div ng-show="loading">
            Loading...
        </div>
        <ul class="list-unstyled">
            <li ng-repeat="message in messages | filter:{name: '!!'}">
                <h1>{{message.name}}</h1>
                <p>
                    Bedrijf: {{message.company}}<br>
                    Reden: {{message.reason}}<br>
                    Email/telefoon: {{message.wayofcontact}}<br>
                </p>
                <button ng-click="messages.$remove(message)" class="btn btn-danger">Verwijder verzoek</button>
                <br><br>
            </li>
        </ul>
        <form ng-submit="addMessage()" novalidate>
            <div class="row">
                <div class="col-xs-6 form-group">
                    <input type="text" class="form-control" id="name" ng-model="name" placeholder="Naam" autofocus required/>
                </div>
                <div class="col-xs-6">
                    <input type="text" class="form-control" ng-model="namecolleague" placeholder="Naam collega" required/>
                </div>
                <div class="col-xs-12 form-group">
                    <input type="text" class="form-control" ng-model="company" placeholder="Bedrijf" required/>
                </div>
                <div class="col-xs-12 form-group">
                    <textarea rows="3" type="text" class="form-control" ng-model="reason" placeholder="Reden van bellen" required></textarea>
                </div>
                <div class="col-xs-12 form-group">
                    <input type="text" class="form-control" ng-model="wayofcontact" placeholder="Email of nummer" required/>
                </div>
                <div class="col-xs-12 form-group">
                    <button type="submit" class="btn btn-primary">Add Message</button>
                </div>
            </div>
        </form>
    </div>
    <script type="text/javascript" src="https://www.gstatic.com/firebasejs/3.6.0/firebase.js"></script>
    <script type="text/javascript" src="https://cdn.firebase.com/libs/angularfire/2.1.0/angularfire.min.js"></script>
    <script type="text/javascript" src="scripts/app.js"></script>
    <script>
    // Initialize Firebase
    var config = {
        apiKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        authDomain: "xxxxxxxxxxxxxxxxxxxx",
        databaseURL: "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
        storageBucket: "xxxxxxxxxxxxxxxx",
        messagingSenderId: "xxxxxxxxxxx"
    };
    firebase.initializeApp(config);
    </script>
</body>
</html>
Run codeHide result
+4
2

-, $qProvider, $q

https://docs.angularjs.org/api/ng/provider/$qProvider

, , , .

app.config(['$qProvider', function ($qProvider) {
    $qProvider.errorOnUnhandledRejections(false);
}]);

, , , , , , .

+3

$loaded():

$firebaseArray(ref).$loaded().then(function(){
    $scope.loading = false;
    document.getElementById('loader').style.display = 'none';
}).catch(function (e) {
    console.log(e);
    throw e;
});

.then, .

AngularJS 1.6.0 .then . , . AngularJS 1.6.1 .

- c9dffde, , promises $exceptionHandler. , , $exceptionHandler ( ) . , (, , $exceptionHandler), promises.

- AngularJS - v1.6 - $q.

. :

0

Source: https://habr.com/ru/post/1664605/


All Articles