【问题标题】:What to send input text data to div将输入文本数据发送到 div 的内容
【发布时间】:2017-01-29 18:01:35
【问题描述】:

html代码

<div style="position: absolute; bottom: 0px; width: 100%">
<div style="text-align: center">
<div>
   {{great}}
</div>
<form>
   <div class="list">
      <div class="list list-inset">
         <label class="item item-input">
         <input type="text" class="form-control input-lg" height="20" placeholder="Add Note" ng-model="searchText">
         </label>
         <button class="button button-block"  ng-click="addTag()">Add Note</button>
      </div>
   </div>
</form>

app.js

$scope.searchText ="  ";
$scope.great = "Note Here";
$scope.addTag = function () {
    $scope.great == $scope.searchText;   
};

我正在尝试为我创建的任务添加注释。这是我的应用程序:

https://behrouz2000.fwd.wf

当您单击任务并单击一个便笺时,它应该会在彼此之上创建一个带有分钟时间戳的便笺。

【问题讨论】:

  • 那么问题是什么?
  • 正如您在链接中看到的,当我单击添加注释时没有任何反应。
  • 使用$scope.great = $scope.searchText; 而不是$scope.great == $scope.searchText;

标签: angularjs binding


【解决方案1】:

当你分配时,你应该使用一个等于

 $scope.great = $scope.searchText;

演示

var app = angular.module("myApp", []);
 app.controller("myCtrl", ['$scope', function($scope) {

   $scope.searchText ="Note Here";
    $scope.great = [];
    $scope.addTag = function () {
        $scope.great = $scope.searchText;
    };
 }]);
<!DOCTYPE html>
<html ng-app="myApp">
<head>
  <meta charset="utf-8" />
  <script src="https://code.angularjs.org/1.4.7/angular.js"></script>
</head>
<body ng-controller="myCtrl">
  <div style="position: absolute; bottom: 0px; width: 100%">
    <div style="text-align: center">
       <div>
            {{great}}
       </div>
       <div class="list">
         <div class="list list-inset">
         <label class="item item-input">
         <input type="text" class="form-control input-lg" height="20" placeholder="Add Note" ng-model="searchText">
         </label>
         <button class="button button-block"  ng-click="addTag()">Add Note</button>
         </div>
         </div>
      </div>
    </div>
    </body>
</html>

【讨论】:

  • 检查链接,我添加了你的代码,仍然没有结果。
  • 我检查了你的代码,点击事件没有在你的链接中触发
  • 它只是打印出一个空白字符串。
  • 当我将 ng-controller="ToDoListCtrl" 添加到我们尝试冻结的 div 时
猜你喜欢
  • 1970-01-01
  • 2015-08-31
  • 2016-01-28
  • 2020-02-16
  • 1970-01-01
  • 2011-12-01
  • 2017-07-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多