问题描述
我正在使用MEAN堆栈.模板引擎是Jade.我需要将用户详细信息从玉传递到角度函数.我的Jade代码如下:
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
在按钮上单击 {user.username} 未定义.我无法将此值从Jade传递给AngularJS.
On button click {user.username} is undefined. I am not able to pass this value from Jade to AngularJS.
推荐答案
我没有使用过Jade,但是在常规html中,在ng-click属性中调用函数时不需要使用{},单击按钮时可能缺少要调用的函数的名称,也许如果尝试使用
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
还可以在控制器中从$ scope变量获取用户名:
Also in your controller you can get the username from the $scope variable:
$scope.myFunction = function(username) {
console.log(username, $scope.user.username);
};
这篇关于将Jade中的用户详细信息传递给Angular函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!