2016-07-25 1 views
1

私はDjango 1.9とAngularJS 1.5を実行しています。ディレクティブが変数に値を与える前にHTMLをレンダリングしています

私のDjangoのビューには、次のようになります。

<-- loading JavaScript files above --> 
<helloWorld><HelloWorld> 

AngularJSコントローラは、DjangoのRESTのAPIからデータを取得している約束をしています

#hello_world_view.py 
def hello_world(request): 
    t = get_template('hello-world.html') 
    return HttpResponse(t.render()) 

HTMLファイルには、次のようになります。

// helloWorld is already defined as an app. 
helloWorld.directive('helloWorldDirective', function() { 
    return { 
     restrict:'E', 
     link: function($scope, $elements, $attributes) { 
      $scope.$watch('someVariable', function(data) { 
       if (data) { 
        $elements.text(data); 
       } 
      }, true); 
     }, 
     templateUrl: '/static/partials/some-template.html' 
    } 
}); 

いくつかのテンプレートが解決され、コントローラからの約束に依存していること内部変数を持っている:それは、ディレクティブは次のようになります。この

helloWorld.controller('helloWorldController', 
    function($scope, $helloWorldService1, $helloWorldService2) { 
     Promise.all([$hWService1, $hWService2]).then(function(response) { 
      $scope.service1 = response[0]; 
      $scope.service2 = response[1]; 
     }); 
    }); 

ようになります。しかし、私はそれを介してテストします。

>>> python manage.py runserver 

変数はレンダリングされません。私は既に{{}}から{[]]にangleJSのタグを変更しました。だから私は、Djangoが誤ってこれらの変数をレンダリングしようとしていないことを知っています。

私も何をしていますか?もしそうなら、修正はありますか?ありがとう。

EDIT:固定文法。

答えて

0

指令のコントローラを登録する必要があるようです。以下を追加してみてください:

コントローラー:指示文の戻りオブジェクトに 'helloWorldController'。

+0

完了しましたが、それは役に立たなかったようです...ありがとう! –

関連する問題