我的选项输入在angularjs中不起作用(my option input is not working in angularjs)

编程入门 行业动态 更新时间:2024-10-27 18:32:33
我的选项输入在angularjs中不起作用(my option input is not working in angularjs)

我正在构建我的第一个角度Web应用程序,我试图部署一个表单,我无法获得我的数据库的选择选项的值我使用下面的代码获取我的数据库的价值。

<div class="form-group"> <label class="control-label" for="basicSelect">Total Hours of Test</label> <label class="select select-o"> <select id="basicSelect" name="basicSelect" ng-model="test.totalTime"> <option value="">- Select One -</option> <option value="1">1</option> <option value="2">2</option> <option value="2.5">2.5</option> </select> </label> </div>

控制器代码

$scope.test = { totalTime: null, testType: null };

我在数据库使用mongodb,在后端使用节点。

表格的其他部分清晰而完整。 但我不能单独得到这个价值。 我在HTML部分出错了。 任何人都可以解雇我。

I am building my first angular web application iam trying to deploy one form and i couldn't get the value of the select option to my database i used the below code for getting my value to the database.

<div class="form-group"> <label class="control-label" for="basicSelect">Total Hours of Test</label> <label class="select select-o"> <select id="basicSelect" name="basicSelect" ng-model="test.totalTime"> <option value="">- Select One -</option> <option value="1">1</option> <option value="2">2</option> <option value="2.5">2.5</option> </select> </label> </div>

controller code

$scope.test = { totalTime: null, testType: null };

i use mongodb at database and node at the backend.

Other parts of the form is getting through clearly and in full shape. but i cant get this value alone. am i going wrong in the html part. Could anyone sort me out.

最满意答案

我认为你想要做的是在值改变时调用函数你可以使用ng-change来调用函数,只要值改变如下:

<!DOCTYPE html> <html> <head> <script data-require="angularjs@1.5.8" data-semver="1.5.8" src="https://opensource.keycdn.com/angularjs/1.5.8/angular.min.js"></script> <link rel="stylesheet" href="style.css" /> <script> var app = angular.module('yourApp', []); app.controller('YourCtrl', function($scope) { $scope.test = { totalTime: null, testType: null }; $scope.selectedTime = function(value) { alert('selectTime ' + value); }; }); </script> </head> <body ng-app="yourApp"> <div ng-controller="YourCtrl"> <div> test.totalTime: {{test.totalTime}} </div> <div class="form-group"> <label class="control-label" for="basicSelect">Total Hours of Test</label> <label class="select select-o"> <select id="basicSelect" name="basicSelect" ng-model="test.totalTime" ng-change="selectedTime(test.totalTime)"> <option value="">- Select One -</option> <option value="1">1</option> <option value="2">2</option> <option value="2.5">2.5</option> </select> </label> </div> </div> </body> </html>

我已经创建了一个向我展示我的想法的东西

I think that what you want to do is call a function when the value is changed you can use ng-change to call a function whenever the value is changed like this:

<!DOCTYPE html> <html> <head> <script data-require="angularjs@1.5.8" data-semver="1.5.8" src="https://opensource.keycdn.com/angularjs/1.5.8/angular.min.js"></script> <link rel="stylesheet" href="style.css" /> <script> var app = angular.module('yourApp', []); app.controller('YourCtrl', function($scope) { $scope.test = { totalTime: null, testType: null }; $scope.selectedTime = function(value) { alert('selectTime ' + value); }; }); </script> </head> <body ng-app="yourApp"> <div ng-controller="YourCtrl"> <div> test.totalTime: {{test.totalTime}} </div> <div class="form-group"> <label class="control-label" for="basicSelect">Total Hours of Test</label> <label class="select select-o"> <select id="basicSelect" name="basicSelect" ng-model="test.totalTime" ng-change="selectedTime(test.totalTime)"> <option value="">- Select One -</option> <option value="1">1</option> <option value="2">2</option> <option value="2.5">2.5</option> </select> </label> </div> </div> </body> </html>

I have created a showing you my idea plunker

更多推荐

本文发布于:2023-07-22 02:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1216024.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中不   选项   angularjs   working   option

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!