ng-init with words in AngularJS

189 Views Asked by At

I am trying to set if the new item being created is a service or a product. I want by default for product to be selected.

<div ng-init="pr.type=Product">
  <div class="form-group">
    <label class="radio-inline">
      <input type="radio" ng-model="pr.type" id="productType" value="Product"> Product
    </label>
    <label class="radio-inline">
      <input type="radio" ng-model="pr.type" id="serviceType" value="Service"> Service
    </label>
  </div>
</div>

If I change the pr.type to be numerical as in 1 for product and 2 for service it works. But that isn't what I want.

Because my field placeholders change as the selected type changes..

<div class="row">
  <div class="col-sm-6">
    <div class="form-group">
      <input type="text" ng-model="pr.upc" class="form-control" placeholder="{{pr.type}} Number"/>
    </div>
  </div>
  <div class="col-sm-6">
    <div class="form-group">
      <input type="text" ng-model="pr.name" class="form-control" placeholder="{{pr.type}} Name"/>
    </div>
  </div>
</div>

Does ng-init not work with words? I would think it wouldn't matter. What am I doing wrong?

1

There are 1 best solutions below

0
On BEST ANSWER

Since your parameter is a string, you need to quote it or the javascript engine will not interpret it as you would like.

To fix it, simply add quotes around the term like this: ng-init="pr.type='Product'"