3

Hi Friends I have radiobuttons "%" and "Count"

If i click "%" then In the text box "%" Should be placeholder

If i click "Count" Then "Count" Should be placeholder for same textbox

Here Fiddle link:http://jsfiddle.net/qbauuzj2/

Html

       <div class="winner-par">
        <p>Winner Parameter</p>
        <div class="onoffswitch-green2">
          <input type="radio" id="radios5" name="radiosg5" class="SwitchOn" value="true" checked 
         ng-click="radioChecked()">
          <label for="radios5">%</label>
          <input type="radio" id="radios6" name="radiosg5" class="SwitchOff" value="false" ng-click="radiounChecked()">
          <label for="radios6">Count</label>
        </div>
      </div>
      <input type="text">
Pragnesh Khalas
  • 2,908
  • 2
  • 13
  • 26
manoji stack
  • 709
  • 1
  • 11
  • 27

2 Answers2

6

You can dynamically update DOM-elements

<div ng-app="" ng-controller="Controller">
    ...
    <input type="text" placeholder="{{placeholder}}" />
</div>

Your controller

function Controller($scope) {

    $scope.radioChecked = function ()
    {
        $scope.placeholder="%";
        $scope.apply();
    }

    $scope.radiounChecked = function ()
    {
        $scope.placeholder="Count";
        $scope.apply();
    }
}

http://jsfiddle.net/z21qfwqz/14/

If you use >1.1.3 angular version - better way for this ng-attr-placeholder(thanks for Teq1)

<input type="text" ng-attr-placeholder="{{placeholder}}" />

Look at this

Igor Semin
  • 2,486
  • 1
  • 20
  • 21
  • 3
    TIP: It's better to use ng-attr-placeholder due to interpolation issues in IE => http://stackoverflow.com/questions/20647572/angularjs-v1-2-5-script-error-with-textarea-and-placeholder-attribute-using-ie11/24272011#24272011 – Teq1 Dec 30 '14 at 13:48
0

Follow this example:

Change value of input placeholder via model?

Depending on which is selected, change the value of the "placeholder" variable in your scope, then bind that variable to the placeholder attribute on the element.

Community
  • 1
  • 1
Peter Ashwell
  • 4,292
  • 2
  • 18
  • 22