javascript - Angularjs: Add placeholder on input with active class - Stack Overflow

I have a list ofinputs created via ng-repeat. Initially all inputs are disabled except the first one.

I have a list of inputs created via ng-repeat. Initially all inputs are disabled except the first one. First input also have an active class (it's red in color because of active class) Planker

When I focus on the first input field 2nd input field bees enabled with same active class. Same for others

So what I am trying to do is, if inputs have active class there will be a "placeholder text" on it. Without active class there should be no placeholder.

How I can add a placeholder dynamically on the input with active class ?

Code:

<div class="col-md-2-4 voffset3" ng-repeat="item in csTagGrp">
  <ul class="list-unstyled cs-tag-item-grp" ng-init="$parentIndex = $index">
     <li class="clearfix" ng-repeat="value in item.csTags">
        <div class="pull-left cs-tag-item-list">
           <input ng-focus="focusItem($index, $parentIndex)"  ng-disabled="!value.active" ng-class='{active: value.active && !value.old}' type="text" class="form-control input-sm">
        </div>
       </li>
   </ul>
</div>

Thanks in advance.

I have a list of inputs created via ng-repeat. Initially all inputs are disabled except the first one. First input also have an active class (it's red in color because of active class) Planker

When I focus on the first input field 2nd input field bees enabled with same active class. Same for others

So what I am trying to do is, if inputs have active class there will be a "placeholder text" on it. Without active class there should be no placeholder.

How I can add a placeholder dynamically on the input with active class ?

Code:

<div class="col-md-2-4 voffset3" ng-repeat="item in csTagGrp">
  <ul class="list-unstyled cs-tag-item-grp" ng-init="$parentIndex = $index">
     <li class="clearfix" ng-repeat="value in item.csTags">
        <div class="pull-left cs-tag-item-list">
           <input ng-focus="focusItem($index, $parentIndex)"  ng-disabled="!value.active" ng-class='{active: value.active && !value.old}' type="text" class="form-control input-sm">
        </div>
       </li>
   </ul>
</div>

Thanks in advance.

Share Improve this question asked Apr 10, 2015 at 17:18 RaihanRaihan 4,0313 gold badges25 silver badges41 bronze badges 1
  • you can create a directive, here is an example – joshvito Commented Apr 10, 2015 at 17:24
Add a ment  | 

2 Answers 2

Reset to default 7

You could set a placeholder on the input conditionaly, and If its true set to some value from the scope for example:

<input placeholder="{{value.active && !value.old ? placeholder : ''}}" ng-focus="focusItem($index, $parentIndex)"  ng-disabled="!value.active" ng-class='{active: value.active && !value.old}' type="text" class="form-control input-sm">

// controller
$scope.placeholder = "something";

See this plunker.

You can add a function to the $scope and check for the active = true on your data model.

//controller
    $scope.getPlaceholder = function (item) {
     if(item.active){
       return item.tags;
     }
   }

//view
<input ng-focus="focusItem($index, $parentIndex)" 
           placeholder="{{getPlaceholder(value)}}"
           ng-disabled="!value.active" 
           ng-class='{active: value.active && !value.old}' 
           type="text" class="form-control input-sm">

I forked your Plink

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744243442a4564813.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信