AngularJS控制器中的输入字段

时间:2018-08-21 12:02:33

标签: javascript angularjs

我是AngularJS的新手,我试图从文本框中获取用户输入,并使用输入来查询端点并填充其下方的文本框。下面是UI

enter image description here

所以在我的

下面是用户界面的.html代码

        <div hidden id="userData">
            <label style="font-size: medium">Enter Input *</label>
            <input name="userData" class="form-control" ng-model="request.userData">
           <div ng-message="required">This field is required</div>
            </div>
            <div class="row form-group">
                <button type="button" class='btn btn-success' ng-click="queryData()">Query</button>
            </div>
            <input name="userName" class="form-control" ng-model="request.userName">
            <div ng-message="required">This field is required</div>
            </div>

在Controller中,我试图获取userData并将其在Odata端点中用作查询参数

    $scope.queryData = function () {

        var sList = getAppData.getCData(`STR?Bar eq '${$scope.request.userData}'`, `Basic ${$scope.key}`)
       ........             
            };

上面的代码不会将任何数据返回到sList,因此尝试将用户输入存储到如下所示的变量中,并像

那样使用
   $scope.queryData = function () {
        var userEntered = ${$scope.request.userData };
        var strainsList = getAppData.getCData(`STR?Bar eq '`+userEntered+`'`, `Basic ${$scope.key}`)
       ........             
            };

以上代码在更多调试中无法正常工作。

当尝试如下所示的硬编码时

var sList = getAppData.getCData(`STR?Bar eq '1234'`, `Basic ${$scope.key}`)

如何将用户输入(userData)输入到Button函数中。

1 个答案:

答案 0 :(得分:-1)

  

根据您对it("Time sensitive check", async () => { var deadLine = Math.round(Date.now() / 1000) + 3; let eventDetails = await contract.createCampaign("Campaign name",deadLine, { from: accounts[0] }); function timeout(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } await timeout(5000); addressFromEvent = eventDetails['logs'][1]['args']['campaignAddress']; let deployedCampaigns = await factory.getCompletedCampaigns(); await assert.equal(addressFromEvent, deployedCampaigns[0]); }); 数据的评论,应该可以进行以下操作。

在混乱的情况下,始终将代码分为两部分,以提高可读性,请使用hard-coded作为转义序列

\