我如何获取该输入值?

时间:2016-02-02 13:24:00

标签: javascript angularjs html5

我在尝试获取这些输入的价值并将它们与对象相关联时遇到了很大的问题" book"当你点击"现在预订! "

无论我在js中声明对象,它都无法正常工作。 这是为了这样的对象:



let tracker = GAI.sharedInstance().defaultTracker
tracker.set("TEST", value: "TEST")        
let builder = GAIDictionaryBuilder.createScreenView()
tracker.send(builder.build() as [NSObject : AnyObject])




我尝试获取值并将它们分配给这样的变量:



            $scope.book = {
                bday_i : new date(day, month, year),
                bday_f : book(bday_i),
                bfrom : getHours(bday_i),
                buntil : getHours(bday_i),
                bresource : "Small meeting room ",
                bmember : "Lucas Gabriel da Costa",
                busercredit : ("4 hours left of", book(bresource)),
                bcoment : "Test"
            }






            $scope.book.bday_i = myForm.day_i.value;
            $scope.book.bday_f = myForm.day_f.value;
            $scope.book.bfrom = myForm.from.value;
            $scope.book.buntil = myForm.until.value;
            $scope.book.bresource = myForm.resource.value;
            $scope.book.bmember = myForm.member.value;
            $scope.book.busercredit = myForm.usercredit.value;
            $scope.book.bcoment = myForm.coment.value;
            $modalInstance.close(result);

      $scope.dayClick = function (date, jsEvent, view, value) {
           $scope.newEventDate = date;


        
            
      var
           
               t =
               '<div class="modal-header">' +
    '<h5>New booking</h5>' + 
    '</div>' +
    '<form ng-model="myForm" name="myForm" id="myForm">'+
    '<div class="modal-body" name="box" >' + 
    '<p>Time: ' + ' ' + '<pre >' + ' Initial date:' +
    '<input id="day_i" class="form-control" type="date" name="day_i" ng-model="day_i" type="text" min = "dia_hj" value="dia_hj"  required />  ' +
    ' Final date:' +
    '<input id="day_f" class="form-control" type="date" name="day_f" ng-model="day_f" type="text" min = "day_i" value="dia_hj"  required />  ' +
    ' From:' +
    ' <input id="from" class="form-control" name="from" ng-model="from" type="time" min = "getHours()"  value="" required  />' +
    ' Until' +
    ' <input id="until" class="form-control" name="until" ng-model="until" type="time" min = "myForm.from.value" value="" required  /> </pre></p>' +
    '<p> Resource:' +
    ' <pre><input id="resource" class="form-control" name="resource" ng-model="resource" type="text" placeholder ="Ex: Small Meeting Room" value="" required /></pre></p> ' +
    '<p> Member: ' +
    ' <pre><input id="member" class="form-control " name="member" ng-model="member" type="text" placeholder="Ex: Lucas Gabriel da Costa" value="" required />  </pre></p>  ' +
    '<p> User credit:' +
    ' <pre><input id="usercredit" class="form-control" name="usercredit" ng-model="usercredit" type="text"  placeholder="Ex: 4 hours included(Small meeting Room)" value=""  required /></pre></p>' +
    'Note:' +
    '<pre><textarea id="coment" ng-model = "coment" name="coment" rows="4" cols="46" placeholder="Insert ur comment"></textarea></pre></form>' +
    // validação:
    '<div ng-hide= " myForm.day_i.$pristine">' +
    '<span  ng-show="myForm.day_i.$error.required "       class="alert alert-danger">  The INITIAL DATE camp is required.      Or a invalid value was inserted    <br/><br/>  </span></div>   ' +
    '<div ng-hide= " myForm.day_f.$pristine">' +
    '<span  ng-show="myForm.day_f.$error.required || (myForm.day_f.value <= myForm.day_i.value)" class="alert alert-danger">  The FINAL DATE camp is required.      Or a invalid value was inserted    <br/><br/>  </span></div>   ' +
    '<div ng-hide =" myForm.from.$pristine">' +
    '<span  ng-show="myForm.from.$error.required "        class="alert alert-danger">  The FROM camp is required.     Or a invalid value was inserted    <br/><br/>  </span></div>   ' +
    '<div ng-hide =" myForm.until.$pristine">' +
    '<span  ng-show="myForm.until.$error.required || myForm.until.value < myForm.from.value" class="alert alert-danger">  The UNTIL camp is required.    Or a invalid value was inserted    <br/><br/>  </span></div>   ' +
    '<div ng-hide="  myForm.resource.$pristine ">' +
    '<span  ng-show="myForm.resource.$error.required "    class="alert alert-danger">  The RESOURCE camp is required. Or a invalid value was inserted    <br/><br/>  </span></div>   ' +
    '<div ng-hide= " myForm.member.$pristine">' +
    '<span  ng-show="myForm.member.$error.required "      class="alert alert-danger">  The MEMBER camp is required.   Or a invalid value was inserted    <br/><br/>  </span></div>   ' +
    '<div ng-hide="  myForm.usercredit.$pristine">' +
    '<span  ng-show="myForm.usercredit.$error.required "  class="alert alert-danger">  The CREDIT camp is required.   Or a invalid value was inserted    <br/><br/>  </span> </div>  ' +
   
    '</div>' +
    '<div class="modal-footer">' +
    '<button ng-click="close(result)" id="b1" ng-model="b1" name="b1" class="btn btn-danger " >Close</button>' + //botão de fechar
    '<button  ng-click="close2(okay) " id="b2" ng-model="b2" name="b2" class="btn btn-success" ng-disabled="myForm.usercredit.$pristine || myForm.day.$pristine || myForm.from.$pristine || myForm.until.$pristine || myForm.resource.$pristine || myForm.member.$pristine "> Book Now! </button>' +
    '</div>'; 
       

           var
          
               modalInstance = $modal.open({
               template: t,
               controller: 'TestDialogController',
               backdrop: "true",
               resolve: {
                   event: function () {
                       return $scope.newEventDate;
                   },
                   stage: function () {
                       return $scope.stage;
                   }
               }
               });
    
             modalInstance.okay.then(
                function () {
                     alert('');
               
;               
           });
      
           modalInstance.result.then(
			function (result) {
			   //console.log('called $modalInstance.close()');
			    alert(result);

			    $scope.addEvent();
			},
			function (result) {
			    //console.log('called $modalInstance.dismiss()');

			    $scope.addEvent();
			}
		);
       
       };
    app.controller('TestDialogController', function ($scope, $modalInstance) {
        $scope.close = function (result) {
            alert(result);
            $modalInstance.close(result);
        }});
&#13;
&#13;
&#13;

The result is this pop up:

1 个答案:

答案 0 :(得分:0)

您的表单在模式中定义,该模式具有自己的控制器和他自己的范围。

所以当你这样做时

power on

在你的输入中,这是绑定变量“直到”ont范围模态的控制器。

所以,如果你想在模态控制器中建立一个像你这样做的对象:

 ng-model="until"

每个领域都相同。 如果您想将这些书籍显示在主视图中,您可以使用发出的事件并在$ rootscope上进行监听。

我不知道你使用哪个模态库,所以我不能说是否是另一个孩子的范围。