2
http://plnkr.co/edit/xUDrOS?p=preview

I want to make my code like this how can I push array in this so that i can edit my data in-line as well as add new data also. and also I want to add some labels when we add or edit fields but not want to show them when the data is displayed

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body>
<div ng-app="myApp">
  <div ng-controller="ClickToEditCtrl">
    <div ng-hide="editorEnabled">
      {{title}}<br/> {{name}}
      <a href="#" ng-click="enableEditor()"><img src="pencil.jpg" style="  height: 20px;"/></a>
    </div>
    <div ng-show="editorEnabled">
      <input ng-model="editableTitle" ng-show="editorEnabled"><br/>
	    <input ng-model="editableName" ng-show="editorEnabled">
      <a href="#" ng-click="save()"><img src="save.png" style="  height: 20px;"/></a>
      
      <a href="#" ng-click="disableEditor()"><img src="cancel.png" style="  height: 20px;"/></a>.
	  
    </div>
  </div>
</div>
<script>
    var app = angular.module('myApp', []);
app.controller('ClickToEditCtrl',function($scope) {
  $scope.title = "Hi! I am aashima";
   $scope.name = "aashima";
   
  $scope.editorEnabled = false;
  
  $scope.enableEditor = function() {
    $scope.editorEnabled = true;
    $scope.editableTitle = $scope.title;
	 $scope.editableName = $scope.name;
  };
  
  $scope.disableEditor = function() {
    $scope.editorEnabled = false;
  };
  
  $scope.save = function() {
    $scope.title = $scope.editableTitle;
	  $scope.name = $scope.editableName;
    $scope.disableEditor();
	
  };
});

</script>
</body>
</html>

1 Answer 1

1

You need to create array my detail in scope as:

$scope.myDetail = [
     {
       "name" : "aashima",
       "title" : "Hi! I am aashima"
     }
     ];

and the you need to push object in this. I have created a plunker it will help you understand how to start. ** it is not complete functionality. If you need further help just comment.

Edit:

Check this updated Plunker

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

2 Comments

thank you its almost helping me but I actually want to show the fields when the add button is clicked not before that.. how can I do that?
I have added an edit, a new plunker check that is that what you want?

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.