1

I am very new to angularjs, i will brief you out what i should achieve

  1. there are three items in a web page, (i) Checkbox (ii) Textbox 1 (iii) Textbox 2

  2. Textbox 1 is always read only with some text in it

  3. on clicking the checkbox, textbox 2 should be editable which is intially readonly and has the text same as that in textbox 1

I have to do it in angularjs

please help

1
  • Have you tried anything? Commented Jan 12, 2015 at 15:31

2 Answers 2

1

since you have the application and the controller, you can do:

  1. Bind the checkbox to a variable doing: <input type="checkbox" ng-model="checked">;
  2. Now your $scope have a property called checked. When the checkbox is checked, $scope.checked value will be true.
  3. On your text fields write ng-readonly="checked";
Sign up to request clarification or add additional context in comments.

Comments

0

Here you go:

HTML file:

<!DOCTYPE html>
<html ng-app="myApp">

<head>
  <meta charset="utf-8" />
  <title>AngularJS Plunker</title>

  <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.3/angular.js"></script>
  <script src="app.js"></script>
</head>

<body ng-controller="MyController">
  <input type="checkbox" ng-model="myCheckbox" ng-change="cbSelected()" />
  <input type="text" ng-model="text1" readonly />
  <input type="text" ng-model="text2" ng-readonly="!myCheckbox" />
</body>

</html>

JS file:

'use strict';
angular.module('myApp', [])
.controller('MyController', function($scope) {

  $scope.text1 = 'some-text';

  $scope.cbSelected = function() {
      if ($scope.myCheckbox) {  // when checked
        $scope.text2 = angular.copy($scope.text1);
      } else {
        $scope.text2 = "";
      }
  };
});

See it working here: http://plnkr.co/edit/vURMjLxArLsRSKZj5o9q?p=preview

Ask question & read documentation if have any doubts.

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.