使用laravel和angularjs在另一个视图中编辑数据

时间:2014-10-21 09:06:05

标签: php angularjs laravel view edit

我必须使用angularjs和laravel制作一个todo应用程序。我是新手。 我总是在我的控制台中收到此错误:

Error: [$parse:syntax] http://errors.angularjs.org/1.3.0/$parse/syntax?p0=todos.id&p1=is%20unexpected%2C%20expecting%20%5B%3A%5D&p2=12&p3=showById(%7B%7Btodos.id%7D%7D)&p4=todos.id%7D%7D)
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js:6:416
at db.throwError (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js:188:402)
at db.consume (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js:189:335)
at db.object (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js:197:110)
at db.primary (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js:188:33)
at db.unary (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js:194:273)
at db.multiplicative (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js:194:6)
at db.additive (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js:193:386)
at db.relational (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js:193:250) <form id="addTodoForm" role="form" ng-init="showById({{todos.id}})" class="ng-pristine ng-valid"> 

我真的不知道这是什么问题。

todoController.js中的

代码:

  $scope.showById = function(id){ 
      //console.log(window.location.pathname.split('/')[1]);
       TodoAPI.show(id)
        .success(function(data){ 
            //console.log(data);
            $scope.todo= data.todos; 
           // console.log($scope.todo);

        })
        .error(function(error){
              console.log(error);
        });
     };
编辑视图中的

代码:

@extends('layouts.frontend')

@section('content')
<div class="row calendarTitle" ng-app="IMDCommunity" ng-controller="TodoController">
<p>{{$task->id}}</p>

     <div class="row calendarTitle" ng-app="IMDCommunity" ng-controller="TodoController" ng-init="showById({{$task->id}})">
            <div class="col-md-12">
                <h2 class="text-center">Edit task item</h2>
            </div>
        </div>
         <form id="addTodoForm" role="form" ng-init="showById(@{{todos.id}})">

         <form id="addTodoForm" role="form" >
          <div class="form-group">
            <label for="task">Task name</label>
            <input ng-model="task.name" type="text" class="form-control" id="task" value="@{{todos.name}}">
            <label for="dueDate">Due date</label>
            <input ng-model="task.dueDate" type="date" class="form-control" id="dueDate" value="@{{todos.dueDate}}">
            <label for="priority">Priority (min: 0, max: 10)</label><br>
            <input class="form-control"  ng-model="task.priority" type="number" name="priority" id="priority"  min="0" max="10" value="@{{todos.priority}}">
          </div>
          <button ng-click="save()" type="submit" class="btn btn-default">Save task</button>
        </form>

@stop

我也做了函数show:

public function show($id)
    {
        // show only one specific notification
        $todos = \Task::find($id);
        $response = array("status" => "success", "todos" => $todos);
        return \Response::json($response);
    }

所以我创建了一个json来存储我的数据。所以我可以将数据显示到我可以编辑这些数据的表单中。有谁看到我犯的错误?

0 个答案:

没有答案