I am trying to delete an empty row in my table. I have to set in my controller an empty object or I get an error message Undefined property can not read 'push' Note that when I comment on the empty object in the controller, Not found in the pipe. Not sure why I do not need it, but I need it in my project [Plunkr] [1]
$ scope.question = {option: [{} ], Option: {number: ''}}; $ Scope.addOption = function () {$ scope.question.options.push ($ scope.question.option); // Option $ scope.question.option = {number: '', Description: ''}}
Simply use:
$ scope.question = {options: [], Options: {number: ''}}; var app = angular Module ('app', []); App.controller ('fctrl', function ($ scope) {$ scope.question = {options: [], Options: {number: '}}} $ scope.addOption = function () {$ scope.question.options Clear the .push ($ scope.question.option); // option $ scope.question.option = {number: '', description: ''}}}
& lt; Script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js" & gt; & Lt; / Script & gt; & Lt; Div ng-app = "app" & gt; & Lt; Div ng-controller = "fctrl" & gt; & Lt; Table & gt; & Lt; Tr ng-repeat = "Question in question. Options" & gt; & Lt; TD & gt; {{$ Index}} & lt; / TD & gt; & Lt; TD & gt; {{Question}} & lt; / TD & gt; & Lt; / TR & gt; & Lt; Table & gt; & Lt; Button ng-click = "add option ()" & gt; Add & lt; / Button & gt; & Lt; / Div & gt; & Lt; / Div & gt;
Comments
Post a Comment