0

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>
3
  • 1
    Hi there! The stackoverflow community enjoys helping out developers achieve their goals, with the premise of helping one's self first. In that regard, have a look at this [link][1] to help you better formulate your question, show your work and help us help you in general. Thanks! [1]: stackoverflow.com/help/how-to-ask Commented Nov 10, 2017 at 21:42
  • You have no ng-app or ng-controller attributes, so no bindings will happen. Try wrapping your inputs and your div with <div ng-app="firstApp" ng-controller="FirstController"> Commented Nov 10, 2017 at 22:01
  • Also, $scope.toic will not be displayed in your input being bound to topic as they are not spelled the same Commented Nov 10, 2017 at 22:02

1 Answer 1

1

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.

2) $scope.toic should be $scope.topic

3) {{Body}} should be {{body}}

4) <button ...><button> should be <button ...></button> (missing / on closing tag)

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.