javascript - Array of Inputs are passing as null in Angularjs -
i've form in i'm displaying values db through webapi. 1 of control having array of values. i've scenario user can edit , save it(put function).
controller :
$scope.put= function () { $scope.item1 = []; $scope.item1 = $scope.cast.split(','); var movie1 = { _movieid: $scope.movid, _title: $scope.movtitle, _releasedate: $scope.movdate, _rating: $scope.movrate, _cast: $scope.item1 }; var result-= myservice.update($scope.movid, movie1); result.then(function (pl) { $scope.message = "updated successfuly"; } html :
<input type="text" ng-model="movid" class="spacebox" size="30" /> <br /> <input type="text" ng-model="movtitle" class="spacebox" size="30" /> <input type="text" ng-model="cast" class="spacebox" size="30" /> <input type="button" ng-value="edit" ng-click="enable()" style="margin-left: 250px; border-radius: 5px;" /> cast input array of string works perfect if user edit , save when try edit other fields id, title , proceed save without modifying casti'm getting error like
$scope.cast.split not function. why , how resolved.
ideally should define scope variables in controller .
$scope.movid = ''; $scope.movtitle= ''; $scope.cast = ''; i prefer creating context object hold scope variables . know why, read - http://www.thinkingmedia.ca/2015/01/learn-how-to-use-scopes-properly-in-angularjs/#use-data-objects-for-primitive-types
$scope.context = { movid : '', movietitle : '', cast : '' }; and html should -
<input type="text" ng-model="context.movid" class="spacebox" size="30" /> <br /> <input type="text" ng-model="context.movtitle" class="spacebox" size="30" /> <input type="text" ng-model="context.cast" class="spacebox" size="30" />
Comments
Post a Comment