Javascript 代码点火器+;AngularJS:如何使用partials?
情况就是这样: 我正在用Codeigniter+Angular Js构建一个应用程序 现在,它是一个简单的应用程序,可以从数据库中获取一些数据并将其显示在表中。 为了进一步构建应用程序,我需要将列表放在一个部分文件夹中,但我无法加载需要包含的文件 这就是问题所在: 如何在Codeigniter+Angular Js项目中使用partials?Javascript 代码点火器+;AngularJS:如何使用partials?,javascript,php,angularjs,codeigniter,partials,Javascript,Php,Angularjs,Codeigniter,Partials,情况就是这样: 我正在用Codeigniter+Angular Js构建一个应用程序 现在,它是一个简单的应用程序,可以从数据库中获取一些数据并将其显示在表中。 为了进一步构建应用程序,我需要将列表放在一个部分文件夹中,但我无法加载需要包含的文件 这就是问题所在: 如何在Codeigniter+Angular Js项目中使用partials? 我需要把partials文件夹放在哪里 这是代码: 文件index.html: <html ng-app="myApp"> <head
我需要把partials文件夹放在哪里 这是代码: 文件index.html:
<html ng-app="myApp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<script src="assets/js/lib/angular.min.js"></script>
<script src="assets/js/lib/angular-route.min.js"></script>
<script src="assets/js/app.js"></script>
<script src="assets/js/controllers.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<h1>Codeigniter + Angular Js App</h1>
<div class="main col-md-12" ng-view></div>
</body>
</html>
}]))
文件controllers.js:
var userControllers = angular.module('userControllers',[]);
userControllers.controller('ListController',['$scope','$http', function ($scope,$http)
{
// Initialising the user array.
$scope.users = [];
// Getting the list of users through ajax call.
$http({
url: 'http://127.0.0.1/Angular/4-SampleApp2/main/json_get_users',
method: "POST",
}).success(function (data) {
$scope.users= data;
});
}]);
现在“partials”文件夹位于“views”文件夹中,其中有一个文件:list.html
不再加载包含用户列表的表。
有人知道如何将部分加载到Codeigniter+Angular项目中?
多谢各位
编辑:
这是控制台中的错误消息:
加载资源失败:服务器响应状态为404(未找到)http://127.0.0.1/Angular/4-SampleApp2/partials/list.html
试试这个:
$routeProvider.
when('/list', {
templateUrl: 'list.html',
controller: 'ListController'
}).
otherwise({
redirectTo: '/list'
});
首先,确保文件夹路径正确
在我的项目中,我使用了codeigniter模块扩展hmvc
我的部分在我的模块视图文件夹下
i、 e
/project/application/modules/mymodule/views/list.html
那我可以用
myApp.config(function($routeProvider) {
$routeProvider.
when('/list', {
templateUrl: '<?=base_url()."mapplication/modules/".$this->router->fetch_module();?>/views/list.html',
controller: 'ListController'
}).
otherwise({
redirectTo: '/list'
});
});
在我的例子中,在modules目录下,我将所有站点都放在子文件夹/ci22中,所以我就是这么做的(工作起来很有魅力):
按照以下步骤让AngularJS路由通过Codeigniter的部分文件夹工作:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Partials extends CI_Controller {
public function view($view)
{
$this->load->view('partials/'.$view);
}
}
您是否有任何.htaccess可以将partial的请求重定向到index.php?(比如说,如果你的.htaccess没有忽略.html文件。)现在“视图”文件夹中有一个.htaccess文件。我认为这是一个codeigniter默认文件。内容是:拒绝一切。我没有创建任何其他.htaccess,文件夹partials中没有.htaccess文件。您已经解决了这个问题吗?我已经尝试过了。正在“视图”文件夹中复制文件,但似乎不起作用。谢谢你在浏览器中做了$scope.users的控制台日志吗?看看list.html是不是根本不显示,还是只是重复一下?谢谢你的提示。我已经编辑了问题,包括控制台中的错误消息。当您刷新二手路线上的页面时,HTML5模式是否正常工作?我是说,不是在你的“装载”路线上。哇,老兄!这个问题已经三年了!无论如何,谢谢:)如果你想回答,你可以查看最新的问题,选择“php”或“angularjs”标记。人们会更加需要帮助!
myApp.config(function($routeProvider) {
$routeProvider.
when('/list', {
templateUrl: '<?=base_url()."mapplication/modules/".$this->router->fetch_module();?>/views/list.html',
controller: 'ListController'
}).
otherwise({
redirectTo: '/list'
});
});
Order allow,deny
Allow from all
.config(['$routeProvider', '$locationProvider',
function($routeProvider, $locationProvider) {
$routeProvider
.when('/adminpanel_controller', {
templateUrl: 'ci22/adminpanel_view.php',
controller: 'DashboardController'
})
.when('/ci22/categorias_controller', {
templateUrl: '/ci22/categorias_controller',
controller: 'Categoriasv2Controller'
})
.when('/ci22/idiomas_controller', {
templateUrl: '/ci22/idiomas_controller',
controller: 'IdiomasController'
});
$locationProvider.html5Mode(true);
}])
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Partials extends CI_Controller {
public function view($view)
{
$this->load->view('partials/'.$view);
}
}
$route['partials/(:any)'] = "partials/view/$1";
myApp.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/list', {
templateUrl: 'partials/list.html',
controller: 'ListController'
}).otherwise({
redirectTo: '/list'
});
}]);