dqrdlqpo775594 2016-03-24 06:28
浏览 45

AngularJS不适用于yii2

I'm trying to get simple Hello World from yii2 layout. AppAsset.php:

...
    public $js = [
       'js/angular.min.js',
    ];
...

layout/main.php:

...
<html lang="<?= Yii::$app->language ?>" ng-app="app">
...
<body ng-contoller="ctrl">
...
    <div class="container">
        {{hello}}
...
<?php $this->endBody() ?>
<?=Html::jsFile('@web/js/app.js')?>
</body>
...

/js/app.js

angular.module('app', [])
       .controller('ctrl', function($scope){
            $scope.hello = 'Hello World!';
            console.log('inside ctrl');
    });

console.log('outside ctrl');

'outside ctrl' works fine. but block 'inside ctrl' doesn't. Page not shows anything about {{hello}}. Where I missed?

  • 写回答

2条回答 默认 最新

  • dongqu7778 2016-03-24 06:51
    关注

    Why are you loading the app js outside the AppAsset? Should be there too in order to work.

    If you dont want to do that at lest load de app js above the endbody function.

    评论

报告相同问题?