i have template text box in directive,on click of button(add) repeating same directive 10 times 10 times text box come ng-model remain same each text box , need make dynamic on each repeat of template ng-model becomes different. problem not able create dynamic ng-model text box distinguish between values entered can access in controller.how make model of text box dynamic.
app.directive("configdirectives", function($compile) { return { restrict: 'ea', link: function(scope, element, $attr) { console.log('scope in directive : ' + scope); scope.add = function() { console.log("inside directive value of satcount", satcount++); $newdirective = angular.element('<add-config></add-config>'); element.append($newdirective); $compile($newdirective)(scope); console.log('scope in directive : ' + scope); } } }).directive("addconfig", function() { return { restrict: 'ae', template: '<div>{{scope.satcount}}' + '<input type="text" ng-model="x"/>' + '</div>', link: function(scope, element, attribute) { scope.remove = function() { element.remove(); } } }); <!-- controller --> (function() { var self = null; var configruleclass = class.extend({ init: function($scope, configservice) { self = this; self.$scope = $scope; }, save: function() { console.log("values parent configuration---"); console.log("config1---", self.lstconfigs.name); console.log("dynamic filed data" + self.dynamicconfigs); } }); app.controller("configrulecntrl", ['$scope', 'configservice', configruleclass]); })(); <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div id="xx" data-ng-controller="configrulecntrl y"> <input type="text" ng-model="y.x" /> <button data-ng-click="add()">add</button> <br> <button data-ng-click="y.save()">save</button> <config-directives></config-directives> </div>
try code create dynamic model on using input
working code clck here
<input type="text" ng-model="newobject[item.name]"> to maintain previous data use copy
var original = data.data; $scope.newobject =angular.copy(original);
Comments
Post a Comment