Pass user details in Jade to Angular function

半城伤御伤魂 提交于 2020-01-06 14:53:15

问题


I am using MEAN stack. The template engine is Jade. I need to pass the user details from jade to angular function. My Jade code is as follows:

extends layout

block content
    div.container
        div.row
            div.col-sm-6.col-md-4.col-md-offset-4
                    h1.text-center.login-title Welcome #{user.username}. User Details
                        div.signup-wall
                            ul.user-details
                                li Username ---> #{user.username}
                                li Email    ---> #{user.email}
                                li First Name ---> #{user.firstName} 
                                li Last Name ---> #{user.lastName}

                        a(href='/signout', class='text-center new-account') Sign Out
                        br
                        div
                            div
                                select
                                    option(ng-repeat='p in projects')
                                        {{ p.name }}
                        br
                        p #{user.username}
                        p #{user.email}
                        form(style="")
                            textarea(type='text', ng-model='formData.workdone', placeholder='Work Done')
                            br
                            br
                            textarea(type='text', ng-model='formData.workdoing', placeholder='Work Doing')
                            br
                            br
                            textarea(type='text', ng-model='formData.blockers', placeholder='Blockers')
                            br
                            br
                            button(type='submit', ng-click='({user.username})' ) Submit

On button click {user.username} is undefined. I am not able to pass this value from Jade to AngularJS.


回答1:


I haven't used Jade but in regular html you don't need to use {} when calling a function in the ng-click attribute, also you are missing the name of the function to call when clicking the button, perhaps if you try with

button(type='submit', ng-click='myFunction(user.username)' ) Submit

Also in your controller you can get the username from the $scope variable:

$scope.myFunction = function(username) {
    console.log(username, $scope.user.username);
};


来源:https://stackoverflow.com/questions/33566648/pass-user-details-in-jade-to-angular-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!