Angularjs routing with django's urls

前端 未结 2 1530
栀梦
栀梦 2021-02-09 01:32

I am using AngularJS for my front-end and Django as a back-end.

I am doing very simple things at the back-end so I have not considered using tastypie.

The proble

2条回答
  •  隐瞒了意图╮
    2021-02-09 01:57

    You have to define the controller as part of the module. Try the following:

    // controller.js
    angular.module('app')
           .controller('EntryCtrl', [
              '$scope',
              '$http',
              '$routeParams',
              '$location',
              'master', // this has to be angular injectable
              function($scope, $http, $routeParams, $location, master) {
                  $scope.form = master.form;
              }
           ]);
    

    and you should only define the app once within the app.js:

    // angular.js
    angular.module('app', ['ngResource'])
           .config([
             '$routeProvider',
             function($routeProvider){
                 $routeProvider
                    .when('/', {
                        templateUrl: '/templates/workflow/request_form.html',
                        controller: 'EntryCtrl'
                    })
                    .otherwise({
                        redirectTo: '/'
                    });
             }
           ]);
    

    Then make sure you include this after you define the angular app within the template:

    
     
     
    

提交回复
热议问题