如何在内联javascript中调用AngularJS Bindings?

时间:2016-07-11 17:33:51

标签: javascript html angularjs

我需要在内联javascript函数中调用AngularJS绑定。我似乎无法将数据传到那里。此外,格式需要以字符串形式到达。

以下是 HTML 中的内联javascript:

<body ng-view>
    <script type="text/javascript">
            $('#comments-container').comments({
                profilePictureURL: 'https://viima-app.s3.amazonaws.com/media/user_profiles/user-icon.png',
                youText: "Angular Binding"   // HERE is where Angular binding needs to be called
                },
                roundProfilePictures: true,
                textareaRows: 1,
                enableAttachments: true,
                getComments: function(success, error) {
                    var commentsArray = [{
                        id: 1,
                        created: '2015-10-01',
                        content: 'Lorem ipsum dolort sit amet',
                        fullname: 'Simon Powell',
                        upvote_count: 2,
                        user_has_upvoted: false
                    }];
                    success(commentsArray);
                },
                postComment: function(commentJSON, success, error) {
                    success(commentJSON);
                },
                putComment: function(data, success, error) {
                    setTimeout(function() {
                        success(data);
                    }, 500);
                },
                deleteComment: function(data, success, error) {
                    setTimeout(function() {
                        success();
                    }, 500);
                },
                upvoteComment: function(data, success, error) {
                    setTimeout(function() {
                        success(data);
                    }, 500);
                },
                uploadAttachments: function(dataArray, success, error) {
                    setTimeout(function() {
                        success(dataArray);
                    }, 500);
                },
            });
    </script>
</body>

以下是我打算用于此部分的 AngularJS控制器

(function () {

angular
.module('meanApp')
.controller('navigationCtrl', navigationCtrl);

navigationCtrl.$inject = ['$location','authentication'];
function navigationCtrl($location, authentication) {
var vm = this;

vm.isLoggedIn = authentication.isLoggedIn();

vm.currentUser = authentication.currentUser();

}

})();

以下是使用此控制器的示例模板

<div class="navbar navbar-default">
<div class="container">
<div id="navbar-main">
  <ul class="nav navbar-nav">
    <li><a href="/">Home</a></li>
  </ul>
  <ul class="nav navbar-nav navbar-right">
    <li ng-hide="navvm.isLoggedIn"><a href="login">Sign in</a></li>
    <li ng-show="navvm.isLoggedIn"><a href="profile">{{ navvm.currentUser.name }}</a></li>
    <li ng-show="navvm.isLoggedIn"><a href="login" onclick="logout()">Logout</a></li>
  </ul>
</div>
</div>
</div>

我在HTML里面评论了它需要的位置。

提前致谢

0 个答案:

没有答案