简体   繁体   English

如何向此Angular JS应用程序添加编辑事件?

[英]How to I add an edit event to this angular js application?

Please, I have this block of code and I'm at a loss on how to add an edit event and button. 拜托,我有这段代码,我对如何添加编辑事件和按钮一无所知。 Any help please? 有什么帮助吗?

<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>

You are close, but you have a few typos and missing information that is causing this to not work: 您接近了,但是您有一些错别字和缺少信息,这导致此功能不起作用:

1) You need to wrap your HTML in an element that has ng-app and ng-controller attributes so angular knows which module/controller to use for the logic in your bindings. 1)您需要将HTML包装在具有ng-appng-controller属性的元素中,以便angular知道要为绑定中的逻辑使用哪个模块/控制器。

2) $scope.toic should be $scope.topic 2) $scope.toic应该是$scope.topic

3) {{Body}} should be {{body}} 3) {{Body}}应该是{{body}}

4) <button ...><button> should be <button ...></button> (missing / on closing tag) 4) <button ...><button>应该是<button ...></button> (在结束标记上缺失/

 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; }; }); 
 <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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM