nouman arshad nouman arshad - 21 days ago 6
AngularJS Question

Databinding and service call in angular js?

I am new in angular js last time i faced a problem so i sort out that was only binding text boxes data with each other so i did it in the following way

<div class="inner" ng-app="" ng-init="lastName , firstName , Tel , Email , dept , destination =''">
<input type="text" id="Text1" ng-model="firstName" value='{{ firstName }}' onkeypress="return ignoreNumeric(event);">
<label>Last Name *</label>
<input type="text" id="Text2" ng-model="lastName" value='{{ lastName}}' onkeypress="return ignoreNumeric(event);">
<label>First Name *</label>
<input type="text" id="Text5" ng-model="firstName" value='{{ firstName }}' onkeypress="return ignoreNumeric(event);">
</div>
<div class="left_w1_fom3 col-lg-3 col-md-3 col-sm-3 col-xs-12">
<label>Last Name *</label>
<input type="text" id="Text6" ng-model="lastName" value='{{ lastName}}' onkeypress="return ignoreNumeric(event);">
</div>


and so on long as required binding between text boxes but i am facing 3 problems now in binding and services so kindly help me to sort out?


  1. If I load data into one name field dynamically on page load and make
    it read only It will automatically populated in other name fields
    but I want that field to be static if i change the data on others
    have no effect on that first field? how to

  2. How to call an angular js service to fill address field when i finish completely filling zip , street , city name ?

  3. What is 2 way binding in angular js and what is bulk copy?


Answer

incase smit plnkr link lost then same is this

  <body ng-app="changeExample">
<script>
 angular.module('changeExample', [])
 .controller('ExampleController', ['$scope', function($scope) {
  $scope.change = function() {
    if($scope.user.zip == 123456)
    {
      $scope.user.address = "123 @ SV USA"
    }
   };
   }]);
 </script>
<div ng-controller="ExampleController">
 <div class="inner" ng-app="" ng-init="lastName , firstName , Tel , Email  
   ,    dept , destination =''">
 <label>Name *</label>
   <input type="text" id="Text1" ng-model="user.name"  onkeypress="return  
  ignoreNumeric(event);">
  <label>ZIP *</label>
  <input type="text" id="Text2" ng-model="user.zip" ng-change="change()"  
 onkeypress="return ignoreNumeric(event);">
 <label>Address *</label>
 <input type="text" id="Text5" ng-model="user.address"  onkeypress="return  
 ignoreNumeric(event);">
</div>
Comments