问题描述:

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.

网友答案:

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);
};
相关阅读:
Top