I am new to Angular.js and what I'm trying to do is adding a lis-item every time the user clicks on #create-new-rule
but the below doesn't seem to be working.
Also, when the user click on li .delete
I want that list-item to be removed from the DOM as well as from the this.rules
array.
app.js
app.controller('RuleController', function()
{
function Rule ()
{
this.name = 'untitled';
this.delete = function ()
{
console.log('removed from DOM as well as from this.rules array');
};
};
this.rules = [];
this.addRule = function ()
{
this.rules.push(new Rule());
};
});
index.html
<div id="rule-controller" ng-controller="RuleController as RuleCtrl">
<ul id="rules">
<li class="rule" ng-repeat="rule in RuleCtrl.rules">
<input type="text" ng-value="rule.name"/>
<div class="delete" ng-click="rule.delete()">delete</div>
</li>
</ul>
<div id="create-new-rule">
<div ng-click="RuleCtrl.add()">create new rule</div>
</div>
</div>