小编Kes*_*hav的帖子

removeEventListener不删除firebase中的侦听器

我想在特定字段的值为true时从firebase ref中删除addValueEventListener侦听器.

ValueEventListener valueListener=null;

private void removeListener(Firebase fb){
    if(valueListener!=null){
        **fb.removeEventListener(valueListener);**
    }
}

String key="https://boiling-heat-3083.firebaseio.com/baseNodeAttempt/" + userId+"/"+nodeType+"/"+nodeId+"/data";
final Firebase fb = new Firebase(key);
valueListener=fb.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot snap) {
        final HashMap<String, Object> data=(HashMap<String, Object>) snap.getValue();
        if( data.get("attemptFinish_"+nodeId)!=null){
            boolean title = (boolean) snap.child("attemptFinish_"+nodeId).getValue();
            if(title){
                removeListener(fb);
            }
        }
    }
    @Override
    public void onCancelled() {
        // TODO Auto-generated method stub
    }
});
Run Code Online (Sandbox Code Playgroud)

但是没有删除addValueEventListener并且为firebase ref调用它.因此,如果需要,请建议我如何从任何firebase ref中删除监听器.

java firebase firebase-realtime-database

12
推荐指数
2
解决办法
2万
查看次数

角度表单验证无法正常工作

我已经在离子角度和应用验证上创建了一个表单.Validations无法正常工作.即使所有字段都是空的点击提交按钮它调用控制器功能.请帮我解决这个问题.

HTML代码

<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Register</h1>
</ion-header-bar>
<ion-content >
<form name="register"  ng-submit="submitDetails(user)" novalidate=""> 
    <div class="list">
        <label class="item item-input item-floating-label" style="position:relative;">
            <span class="input-label">First Name</span>
            <input type="text" placeholder="First Name" ng-model="user.firstName" ng-required="true">
            <p ng-show="user.firstName.$invalid && !user.firstName.$pristine" class="help-block">You name is required.</p>
        </label>
        <label class="item item-input item-floating-label">
            <span class="input-label">Email</span>
            <input type="email" placeholder="Email" ng-model="user.email" ng-required="true">
            <p ng-show="user.email.$invalid && !user.email.$pristine" class="help-block">Enter a valid email</p>
        </label>
        <label class="item item-input item-floating-label">
            <span class="input-label" >Phone no</span>
            <input type="number" placeholder="Phone No" ng-model="user.phone" ng-minlength="10" ng-maxlength="10" ng-required="true">
            <span class="help-block" ng-show="user.phone.$error.required || user.phone.$error.number">Valid …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs ionic

6
推荐指数
1
解决办法
2万
查看次数

不能在指令中使用$ uibModal但可以在控制器中访问

我想制定一个指令来打开一个模态.但$ uibModal未在指令内定义.

var app=angular.module("app",['ui.bootstrap']);

app.controller('AppCtrl', function ($scope, $uibModal) {
    console.log("$uibModal controller",$uibModal);//getting object
});

app.directive('showPopUp',function() {
    return {
        restrict: 'EA',
        link: function(scope, el, attrs,$uibModal) {
            console.log("$uibModal",$uibModal);//undefined here
                var modalInstance = $uibModal.open({
                  animation: $scope.animationsEnabled,
                  templateUrl: 'popup.html',
                });

                modalInstance.result.then(function (selectedItem) {
                  scope.selected = selectedItem;
                }, function () {
                });

        }  
    }
});
Run Code Online (Sandbox Code Playgroud)

如何在我的指令中使用$ uibModal来打开模态?

angularjs angularjs-directive bootstrap-modal

5
推荐指数
1
解决办法
3760
查看次数