jeudi 18 février 2016

Trying to add a checklist in a Rails App with Angular.js

I'm building a simple task list application with Angular.js. Here are my parameters for tasks:

t.name = string
t.finished = boolean

Here is what I currently have in application.js folder

var ToDoListApp = angular.module("ToDoListApp", []);

    ToDoListApp.controller('tasks', function($scope, $http) {
        $scope.list = [];
        $scope.name = name;
        $scope.finished = false; 

        var promise = $http.get('/tasks.json');
        promise.success(function(data) {
            $scope.list = data;
        });
     $scope.addTaskToList = function() {
     $scope.list.push({ name: $scope.name, finished: $scope.finished});
        $scope.checkboxModel = {
           value1 : false;
       }
    }
    });

And here's what I have in my application.html.erb folder.

<button ng-click="addTaskToList()">Add to List </button>
    Task: <input type ="text" ng-model="name"> <br>
    Is it finished? <input type="checkbox"
           ng-model="string"
           [name="finished"]
           [ng-true-value="true"]
           [ng-false-value="false"]
           [ng-change="string"]>


     <ul> 
        <li ng-repeat="item in list"> 
        Task {{ item.name }} is finished? {{ item.finished }}
            </li>
    </ul>

So for some reason I can't get my checkbox to work. Can anyone offer some insight here? I'd really appreciate any help.




Aucun commentaire:

Enregistrer un commentaire