0

I have a form to input the name and then when I click the submit button the input value should be displayed in the table. please find the below code that I wrote.

model.html

<html>
<body ng-controller="myController">
<form ng-submit="addRow()">
<input type="text" ng-model="name"/>
<input type="submit" value="value"/> 
<form/>

<table>
<tr ng-repeat="record in records">
<td>{ {record.name} }<td/>
<tr/>
<table/>
<body/>
<html/>

script.js

myApp.controller('testController,[$scope',function($scope)
{
$scope.records=[];
$scope.addRow = function()
{
$scope.records.push({'name': $scope.name});
};
}]);

But the output table cell shows as { {record.name} }. I want to print the name which I am typing in the text box

1 Answer 1

0

make sure to fix the following :

  • add ng-app directive to your html and define your module in the js.

  • controller name is different on your html from what you have in you javascript

    • please make sure to close your quotations for 'testController' in js and '$scope' variables.

here is a working jsFiddle link html :

  <body ng-app='myApp' ng-controller="testController">
    <form ng-submit="addRow()">
      <input type="text" ng-model="name" />
      <input type="submit" value="value" />
      <form/>

      <table>
        <tr ng-repeat="record in records">
          <td>{{record.name}} <td/>
         <tr/>
       <table/>
   <body/>
<html/>

javsacript

myApp = angular.module('myApp', []);

myApp.controller('testController', ['$scope', function($scope) {
  $scope.records = [];
  $scope.addRow = function() {
    $scope.records.push({
      'name': $scope.name
    });
  };
}]);
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.