参数控制器不起作用,在Error时未定义

时间:2015-01-31 03:06:20

标签: javascript php angularjs laravel controller

我使用AngularJS + Laravel作为我的网络应用程序。 AngularJS安装在public / app文件夹中,我的web应用程序的视图不是来自public / app,来自Laravel / app / view文件夹。

-views
--web-app
---partials
---chat-rooms.blade.php
--index.blade.php

Index.blade.php

<body ng-app='chatApp'>
    <div class="page-header">
        <h1> Chat application </h1>
    </div>
    <div ng-view class="container"></div>
    {{ HTML::script('app/libs/angular/angular.min.js')}}
    {{ HTML::script('app/libs/angular-route/angular-route.min.js')}}
    {{ HTML::script('app/scripts/app.js')}}
    {{ HTML::script('app/scripts/controllers/chat-rooms.js')}} 
</body>

聊天-rooms.blade.php

<div class="row">
<div class="col-md-12">
    <select class="form-control" ng-model="selectedChatRoom" ng-options="chatRoom.name for chatRoom in chatRooms">
    </select>
    <button type="button" ng-click="selectChatRoom(selectedChatRoom)">Select chat room</button>
</div>
<div class="col-md-12">
    <input type="text" class="form-control" ng-model="chatRoom.name" placeholder="Enter chat room name">
    <button type="button" ng-click="createChatRoom(chatRoom)">Create</button>
</div>

我的app.js来自public / app文件夹:

'use strict';
angular.module('chatApp', ['ngRoute'])
.config(function($routeProvider) {

    $routeProvider

    .when('/', {
        templateUrl: 'partials/chat-rooms',
        controller: 'ChatRoomsCtrl'
    })

    .when('/chat-room/:chatRoom', {
        templateUrl: 'partials/chat-room.html',
        controller: 'ChatRoomCtrl'
    });
});

现在的问题是&#34; ChatRoomsCtrl&#34;导致此问题,该函数未定义。 这是js:

'use strict';

angular.module('chatApp')
.controller('ChatRoomsCtrl', function($scope, ChatRoom, $location) {


    var chatRoomsLoaded = function(chatRooms) {
        $scope.chatRooms = chatRooms;
    }

    var handleErrors = function(response) {
        console.error(response);
    }


    $scope.selectChatRoom = function(chatRoom) {

        $location.path('chat-room/' + chatRoom.id);
    }

    $scope.createChatRoom = function(chatRoom) {

        ChatRoom.create(chatRoom).then($scope.selectChatRoom);
    }


    ChatRoom.getAll()
        .then(chatRoomsLoaded)
        .catch(handleErrors);

});

同样,一切似乎都有效,前端可以工作,但后端无法实现。创建按钮&#34; ng-click&#34;根本没有切换。似乎控制器正在造成这种情况。


我的index.blade.php的一部分实际上放在我的视频模板中。 我的视频模板包含videoController和route ...

的视频控制器

public function getChatRoom()
{
    return View::make('chat-app.partials.chat-rooms');
}

路线

Route::get('video/{slug}', array(
'as' => 'showVideo',
'uses' => 'VideoController@show'
));

Route::get('video/partials/chat-rooms', array(
'uses' => 'VideoController@getChatRoom'
));

当我加载聊天室时,网址必须是视频/部分/聊天室..目前我正在浏览视频模板,其中一部分是聊天应用,网址是视频/ {slug} / slug可以是任何名字......

错误: Click here to view the error

0 个答案:

没有答案