2014-01-07 49 views
1

再次我......我卡住了。我需要在我的项目中使用Angular.JS,但我无法在动态生成的标签中运行Angular。Angular.JS动态jQuery

<h1>Your albums</h1><hr/> 
    <div ng-controller="AlbumsController"> 
     <ul> 
      <li ng-repeat="album in albums"> 
       {{album.name}} 
       <p>{{album.desc}}</p> 
      </li> 
     </ul> 
    </div> 

这是通过JQuery动态生成的块。

<html ng-app="Application" class="no-js" lang="ru"> 

这是标记静态,它必须初始角。

我的动态块不起作用。它返回:{{album.name}} {{album.desc}},这就是未初始化 Angular.JS :(

var Juster = angular.module('Juster', []); 
Juster.controller('AlbumsController', function ($scope) {  
    $.post("/index.php/profile_ctrl/myalbums", function(data){ 
     $scope.albums = data; 
    }) 
}); 
+1

你能告诉我们你的Controller/Js? –

+0

var Juster = angular.module('Juster',[]); Juster.controller( 'AlbumsController',函数($范围){$ .post的( “/ index.php的/ profile_ctrl/myalbums”,功能(数据){$ = scope.albums数据; }) } ); 所以,html: – user3169724

+0

在我记起Angular之后,我开始在JQuery上创建项目。它有助于简单显示json – user3169724

回答

1

马特是正确的话,你需要放开的迹象jQuery的大部分在使用的角度与控制器和指令工作时,它有时会让人头痛

要使用只在您的示例角度我会使用像这样的$ HTTP服务:

Juster.controller('AlbumsController', function ($scope, $http) { 

    $http({method:'GET', url: '/index.php/profile_ctrl/myalbums'}) 
     .success(function(data, status, headers, config) { 
      $scope.albums = data; 
     }) 
     .error(function(data, status, header, config) { 
      // Handle error 
     }); 
});