如何在此角度js应用程序中添加编辑事件?

时间:2017-11-10 21:34:29

标签: javascript angularjs

请问,我有这段代码,而且我对如何添加编辑事件和按钮感到茫然。有什么帮助吗?

<script>
  var firstApp = angular.module('firstApp', []);
  firstApp.controller('FirstController', function($scope) {
    $scope.toic = '';
    $scope.discussion = '';
    $scope.updateMessage = function() {
      $scope.heading = $scope.topic;
      $scope.body = $scope.discussion;
    };
  });
</script>
<input ng-model="topic">
<input ng-model="discussion">
<button ng-click="updateMessage()">click<button>

<div>
{{heading}} 
{{Body}}
</div>

1 个答案:

答案 0 :(得分:1)

你很接近,但是你有一些错别字和丢失的信息导致它无效:

1)您需要将HTML包装在具有ng-appng-controller属性的元素中,以便angular知道哪个模块/控制器用于绑定中的逻辑。

2)$scope.toic应为$scope.topic

3){{Body}}应为{{body}}

4)<button ...><button>应为<button ...></button>(在结束标记时丢失/

&#13;
&#13;
var firstApp = angular.module('firstApp', []);
firstApp.controller('FirstController', function($scope) {
  $scope.topic = '';
  $scope.discussion = '';
  $scope.updateMessage = function() {
    $scope.heading = $scope.topic;
    $scope.body = $scope.discussion;
  };
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="firstApp" ng-controller="FirstController">
  <input ng-model="topic">
  <input ng-model="discussion">
  <button ng-click="updateMessage()">click</button>

  <div>{{heading}} 
  {{body}} </div>
</div>
&#13;
&#13;
&#13;