angularjs partials with codeigniter

时间:2015-01-08 00:13:21

标签: angularjs codeigniter

我是angularjs的新手,我在codeigniter中加载partials时遇到了问题。

控制器:

function angular(){
$this->load->view('admin/header');
$this->load->view('admin/angulardata');
$this->load->view('admin/footer');
}

angulardata.php

<div class="right">

    <div ng-view>
    </div>

</div>

angular.js

 var artistControllers=angular.module('artistControllers',[]);
artistControllers.controller('ListController',function($scope){
$scope.artists=[
  {
    "name":"Barot Bellingham",
    "shortname":"Barot_Bellingham",
    "reknown":"Royal Academy of Painting and Sculpture",
    "bio":"Barot has just finished his final year at The Royal Academy of Painting and Sculpture, where he excelled in glass etching paintings and portraiture. Hailed as one of the most diverse artists of his generation, Barot is equally as skilled with watercolors as he is with oils, and is just as well-balanced in different subject areas. Barot's collection entitled \"The Un-Collection\" will adorn the walls of Gilbert Hall, depicting his range of skills and sensibilities - all of them, uniquely Barot, yet undeniably different"
  },
  {
    "name":"Jonathan G. Ferrar II",
    "shortname":"Jonathan_Ferrar",
    "reknown":"Artist to Watch in 2012",
    "bio":"The Artist to Watch in 2012 by the London Review, Johnathan has already sold one of the highest priced-commissions paid to an art student, ever on record. The piece, entitled Gratitude Resort, a work in oil and mixed media, was sold for $750,000 and Jonathan donated all the proceeds to Art for Peace, an organization that provides college art scholarships for creative children in developing nations"
  },
  {
    "name":"Hillary Hewitt Goldwynn-Post",
    "shortname":"Hillary_Goldwynn",
    "reknown":"New York University",
    "bio":"Hillary is a sophomore art sculpture student at New York University, and has already won all the major international prizes for new sculptors, including the Divinity Circle, the International Sculptor's Medal, and the Academy of Paris Award. Hillary's CAC exhibit features 25 abstract watercolor paintings that contain only water images including waves, deep sea, and river."
  },
  {
    "name":"Hassum Harrod",
    "shortname":"Hassum_Harrod",
    "reknown":"Art College in New Dehli",
    "bio":"The Art College in New Dehli has sponsored Hassum on scholarship for his entire undergraduate career at the university, seeing great promise in his contemporary paintings of landscapes - that use equal parts muted and vibrant tones, and are almost a contradiction in art. Hassum will be speaking on \"The use and absence of color in modern art\" during Thursday's agenda."
  },
  {
    "name":"Jennifer Jerome",
    "shortname":"Jennifer_Jerome",
    "reknown":"New Orleans, LA",
    "bio":"A native of New Orleans, much of Jennifer's work has centered around abstract images that depict flooding and rebuilding, having grown up as a teenager in the post-flood years. Despite the sadness of devastation and lives lost, Jennifer's work also depicts the hope and togetherness of a community that has persevered. Jennifer's exhibit will be discussed during Tuesday's Water in Art theme."
  }


]

});

app.js

 var myApp=angular.module('myApp',[
'ngRoute',
'artistControllers'

]);
myApp.config(['$routeProvider',function($routeProvider){
$routeProvider.
when('/list',{
templateUrl:'partials/list.php',
controller:'ListController'
}).otherwise({
redirectTo:'/list'
});



}]);

和list.php,位于views / admin / partials / list.php

    <div>
<input ng-model="query" placeholder="Search for Artists">
</div>
    <ul>
        <li ng-repeat="item in artists | filter: query">
        <div>
        <h2>{{item.name}}</h2>
        <h3>{{item.reknown}}</h3>
        </div>
        </li>
    </ul>

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:2)

解决方案:只需更改一行。

第一种方式: -

在此处提供完整路径:

templateUrl:'partials/list.php',

将其更改为:

templateUrl:'[full-path]/partials/list.php',

例如 [full-path] = http://localhost/mysystem/

第二种方式: -

您可以将基本路径存储为javascript变量:

var base_url="http://localhost/mysstem/";

,代码行变成这样:

templateUrl:base_url+'partials/list.php',

希望它有所帮助。