2015-01-08 80 views
1

我是angularjs的新手,我在codeigniter中加載partials時遇到了問題。angularjs partials with codeigniter

控制器:

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的,位於景色/管理/諧音/ 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> 

我怎樣才能使這項工作?

+0

我知道這是一個愚蠢的問題,但是......您是否嘗試過使用其他網址作爲您的'templateUrl'?像'application/views/partials/list.php'或甚至僅僅使用'views /'部分。 – klauskpm

+0

@klauskpm是的,我已經嘗試過,沒有任何東西 – admir

+0

如果你替換'.html'文件的'list.php',它的工作原理?可能是一些配置。甚至文件權限問題。因爲,如你所說,它是路由確定。那麼......我的根目錄是** game-on **,我的** app.routes.js **在'game-on/app'上,但是我的路線指向'app/components/home/homeView.html'。 – klauskpm

回答

2

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

第一種方式: -

充分路徑在這裏:

templateUrl:'partials/list.php', 

將其更改爲:

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

EG。[full-path] = http://localhost/mysystem/

方式二: -

您可以存儲基本路徑到JavaScript變量:

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

和代碼行變成這樣:

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

希望能幫助到你。