Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 使用jade表单进行双向数据绑定_Angularjs_Pug - Fatal编程技术网

Angularjs 使用jade表单进行双向数据绑定

Angularjs 使用jade表单进行双向数据绑定,angularjs,pug,Angularjs,Pug,我试图使用ngModel将两个文本输入字段附加到$scope。这是我的密码: extends layout block content h1 hello from partials form(name='login') label(for='username') username input(type='text' name='username' id='username' ng-model='credentials.username'

我试图使用ngModel将两个文本输入字段附加到$scope。这是我的密码:

extends layout

block content
    h1 hello from partials
    form(name='login') 
        label(for='username') username
            input(type='text' name='username' id='username' ng-model='credentials.username')
    br
    label(for='password') password
        input(type='text' name='password' id='password' ng-model='credentials.password')
    button(type='submit') submit
即使在我按下submit之后,$scope上的凭据也不会更改。默认情况下,它们被设置为空字符串,并在提交后保持这种状态。我的玉表写得不对吗

控制器代码如下所示:

myApp.controller('mainController' , function($scope){
    window.scope = $scope;
    $scope.credentials = {username: '' , password: ''}
})
doctype html
html(ng-app='myApp')
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
  body
    div(ng-controller='mainController')
    block content
    script(src='//ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js')
    script(src='https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular-route.js')
    script(src='/javascripts/myApp.js')
和layout.jade如下所示:

myApp.controller('mainController' , function($scope){
    window.scope = $scope;
    $scope.credentials = {username: '' , password: ''}
})
doctype html
html(ng-app='myApp')
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
  body
    div(ng-controller='mainController')
    block content
    script(src='//ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js')
    script(src='https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular-route.js')
    script(src='/javascripts/myApp.js')

您的
块内容
没有嵌套在控制器下,这就是为什么
ng model
没有更改您的范围

这将有助于:

div(ng-controller="mainController")
  block content

但无论如何,您可能需要一个每页控制器(尽管您仍然可以保留这个控制器-控制器的行为类似于层次结构,与JS原型的方式相同)

这里没有足够的代码来确定问题所在。在保存模型的范围视图中,相关的
ng控制器
在哪里?您在视图中的何处输出值?ng控制器位于layout.jade内。我只是第一次测试Angular,所以我不确定是否应该为每个视图分配ng控制器。这些值不会输出到任何地方。我只是想看到它们附加了$scope对象。原来ng控制器需要分配给每个视图中的一个div。这完全成功了,$scope现在正在更新。