2017-03-12 1 views
1

이것은 Angular JS를 배우기위한 프로젝트입니다. 연락처를 기록하고 편집 할 수있는 단일 페이지 웹 응용 프로그램입니다. 필자가 알 수없는 몇 가지 이유 때문에 Firebase에 데이터를 게시 할 때마다 내 웹 페이지가 정지됩니다. 아무도 이것으로 도울 수 있습니까? 확인하면서양식 제출 후 각도 js- 웹 페이지가 멈 춥니 다

이 내 자바 스크립트 파일을 여기

'use strict'; 
 

 
angular.module('myContacts.contacts', ['ngRoute','firebase']) 
 

 
.config(['$routeProvider', function($routeProvider) { 
 
    $routeProvider.when('/contacts', { 
 
    templateUrl: 'contacts/contacts.html', 
 
    controller: 'contactsCtrl' 
 
    }); 
 
}]) 
 

 
.controller('contactsCtrl', ['$scope','$firebaseArray', function($scope, $firebaseArray) { 
 
    var ref = firebase.database().ref(); 
 
    $scope.contacts = $firebaseArray(ref); 
 
    //console.log($scope.contacts); 
 
    $scope.showAddForm = function(){ 
 
     $scope.addFormShow = true; 
 
    } 
 
    
 
    $scope.hide = function(){ 
 
     $scope.addFormShow = false; 
 
    } 
 
    
 
    $scope.addFormSubmit = function(){ 
 
     console.log('adding contact'); 
 
     
 
     //Assign values 
 
     if($scope.name){var name = $scope.name}else {name=null;} 
 
     if($scope.email){var email = $scope.email}else {email=null;} 
 
     if($scope.company){var company = $scope.company}else {company=null;} 
 
     if($scope.mobile_phone){var mobile_phone = $scope.mobile_phone}else { mobile_phone=null;} 
 
     if($scope.home_phone){var home_phone = $scope.home_phone}else {home_phone=null;} 
 
     if($scope.work_phone){var work_phone = $scope.work_phone}else {work_phone=null;} 
 
     if($scope.street_address){var street_address = $scope.street_address}else {street_address=null;} 
 
     if($scope.city){var city = $scope.city}else {city=null;} 
 
     if($scope.province){var province = $scope.province}else {province=null;} 
 
     if($scope.postal_code){var postal_code = $scope.postal_code}else {postal_code=null;} 
 
     
 
     //Build Object 
 
     $scope.contacts.$add({ 
 
      name:name, 
 
      email:email, 
 
      company:company, 
 
      phone:[ 
 
       { 
 
        mobile:mobile_phone, 
 
        home:home_phone, 
 
        work:work_phone 
 
       } 
 
      ], 
 
      address:[ 
 
       { 
 
        street_address:street_address, 
 
        city: city, 
 
        province: province, 
 
        postal_code: postal_code 
 
       } 
 
      ]     
 
     }).then(function(ref){ 
 
      var id = ref.key(); 
 
      console.log('added contact with id: '+ id); 
 
      //clear form 
 
      clearFields(); 
 
      hide form 
 
      $scope.addFormShow = false; 
 
      
 
      //send message 
 
      $scope.msg ="contact Added"; 
 
     }); 
 
     
 
    } 
 
    
 
    //Clear $scope Fields 
 
     function clearFields(){ 
 
     console.log('Clearing All Fields'); 
 
     $scope.name = ''; 
 
     $scope.email = ''; 
 
     $scope.company = ''; 
 
     $scope.mobile_phone = ''; 
 
     $scope.home_phone = ''; 
 
     $scope.work_phone = ''; 
 
     $scope.street_address = ''; 
 
     $scope.city = ''; 
 
     $scope.province = ''; 
 
     $scope.postal_code = ''; 
 
    } 
 
    
 
    
 
}]);

및 HTML 파일

<div class="row" ng-controller="contactsCtrl"> 
 
    <div class="large-10 columns"> 
 
     <!--<div data-alert ng-show="msg" class="alert-box">{{msg}}</div>--> 
 
    <form ng-submit="addFormSubmit()" ng-show="addFormShow"> 
 
     <h3>Add Contact</h3> 
 
     <!--Add Form--> 
 
     <div class="row"> 
 
      <div class="large-6 columns"> 
 
       <label>Name: 
 
        <input type="text" ng-model="name" placeholder="Contact Name" required/> 
 
       </label> 
 
      </div> 
 
      <div class="large-6 columns"> 
 
       <label>Email: 
 
        <input type="text" ng-model="email" placeholder="Contact Email" required/> 
 
       </label> 
 
      </div> 
 
     </div> 
 
     <div class="row"> 
 
      <div class="large-6 columns"> 
 
       <label>Company: 
 
        <input type="text" ng-model="company" placeholder="Company Name"/> 
 
       </label> 
 
      </div> 
 
      <div class="large-6 columns"> 
 
       <label>Work Phone: 
 
        <input type="text" ng-model="work_phone" placeholder="Work Phone"/> 
 
       </label> 
 
      </div> 
 
     </div> 
 
     <div class="row"> 
 
      <div class="large-6 columns"> 
 
       <label>Mobile Phone: 
 
        <input type="text" ng-model="mobile_phone" placeholder="Mobile Phone" /> 
 
       </label> 
 
      </div> 
 
      <div class="large-6 columns"> 
 
       <label>Home Phone: 
 
        <input type="text" ng-model="home_phone" placeholder="Mobile Phone"/> 
 
       </label> 
 
      </div> 
 
     </div> 
 
     <div class="row"> 
 
      <div class="large-6 columns"> 
 
       <label>Street Address: 
 
        <input type="text" ng-model="street_address" placeholder="Street Name"/> 
 
       </label> 
 
      </div> 
 
      <div class="large-6 columns"> 
 
       <label>City: 
 
        <input type="text" ng-model="city" placeholder="City"/> 
 
       </label> 
 
      </div> 
 
     </div> 
 
     <div class="row"> 
 
      <div class="large-6 columns"> 
 
       <label>Province: 
 
        <input type="text" ng-model="state" placeholder="Province"/> 
 
       </label> 
 
      </div> 
 
      <div class="large-6 columns"> 
 
       <label>Postal Code: 
 
        <input type="text" ng-model="postal_code" placeholder="Postal Code"/> 
 
       </label> 
 
      </div> 
 
     </div> 
 
     <div class="row"> 
 
      <div class="large-12 columns">  
 
       <input type="submit" value="Add Contact" class="button"/> 
 
      </div> 
 
      
 
     </div> 
 
    </form> 
 
    
 
    <h3>Your Contacts (3)</h3> 
 
     <table> 
 
      <thead> 
 
       <tr> 
 
        <th width="200px">Name</th> 
 
        <th width="200px">Company</th> 
 
        <th width="25%">Email</th> 
 
        <th width="25%">Actions</th> 
 
       </tr> 
 
      </thead> 
 
      <tbody> 
 
       <tr ng-repeat="contact in contacts"> 
 
        <td><a href="#">{{contact.name}}</a></td> 
 
        <td>{{contact.company}}</td> 
 
        <td>{{contact.email}}</td> 
 
        <td><a class="button tiny" ng-click="showEditForm(contact)">Edit</a><a class="button tiny alert" ng-click="removeContact(contact)">Delete</a></td> 
 
       </tr> 
 
      </tbody> 
 
     </table>  
 
    </div> 
 
    <div class="small-12 large-2 columns"> 
 
      <a class="button large" ng-click="showAddForm()" ng-hide="addFormShow">+</a> 
 
      <a class="button large" ng-click="hide()" ng-show="addFormShow">-</a> 
 
    </div> 
 
</div>

답변

0

에게 당신의 code 아마도 firebase 모듈을 초기화하지 않는다고 생각합니다.

그래서 당신은 처음

구성 firebase.initializeApp을 (해야한다) 또는이

.config(function() { 
     var config = { 
       apiKey: "", 
       authDomain: "", 
       databaseURL: "", 
       storageBucket: "", 
       messagingSenderId: "" 
      }; 
     firebase.initializeApp(config); 
    }); 

확인이 예는, 그것을 만들기 위해 자신의 중포 기지 초기화 정보를 사용하십시오 작동하지 않습니다 나는 muy 테스트에서 코드 작업을했다.

예 : https://jsfiddle.net/moplin/zLozccap/

enter image description here

관련 문제