jjzjj

javascript - Angular 不在表格行中显示数据。 ng-repeat 不起作用

coder 2024-04-17 原文

我正在尝试使用 Angularjs。问题是,ng-repeat 在路由中时不起作用。它在不在 route 时起作用。

这是我目前所拥有的: 查看链接..

这很好用... http://plnkr.co/edit/1syQFJdMyRUYncBrREue?p=preview

但在这方面,它现在不起作用..(亲自导航) http://plnkr.co/edit/gsi2mZpnU0YJUUOa20DO?p=preview

html

<html ng-app="myApp">
<head>
    <title>Confirm Dialog Box</title>
 <!-- 
    in the link above i create a custom dialog box
 -->
</head>
<body>

<div ng-controller="loglistController">
<table>
  <tr ng-repeat="x in names">
    <td onclick="showDialog()" ng-click="showInEdit(x)">{{ x.Name }}</td>
    <td onclick="showDialog()" ng-click="showInEdit(x)">{{ x.Country }}</td>
  </tr>
</table>


             <div id="white-background">
</div>
<div id="dlgbox">
    <div id="dlg-header"><h3>Information</h3></div>
    <div id="dlg-body">
      Name <input type="text" ng-model="selectedPerson.Name" /><br/>
      Country <input type="text" ng-model="selectedPerson.Country" /><br/>


    </div>
    <div id="dlg-footer">
        <button onclick="dlgOK()">Update</button>
        <button onclick="dlgCancel()">Exit</button>
    </div>
</div>

棱 Angular 分明

var myApp = angular.module('myApp', ['ngRoute']);

myApp.controller('loglistController', ['$scope', '$http', function ($scope, $http) {

    $scope.data=[];
    $scope.selectedPerson={ Name:"",Country:""}; 

            $http.get("loglistajax.php")
                .then(function (response) {$scope.names = response.data.records;});

    $scope.showInEdit=function(person){
    $scope.selectedPerson = person;
    };



 }]);

最佳答案

这是我的 version

我同意大多数points imbalind 提到的。

再补充几点:

  • 我们不应该多次实例化同一个应用程序(在最初的 Plunker 中,我们在 index.html 和 list.html 中都有它)。这里有两种情况:

    var myApp = angular.module('myApp', ['ngRoute']); //new instance of 'myApp' 
    
    var myApp = angular.module('myApp'); //simply handle to 'myApp'
    
  • 我们有两个属于同一个 angular.module'loglistController',它们无法正常工作

  • angular 本身被加载到两个 html 文件中,不好。

  • 对于特定的 Plunker,app.js 中的固定路由:

    .when('/', {
        templateUrl: '/index.html',
        controller: 'mainController'
    })
    
  • 请不要混淆 jQuery 脚本,它会在以后造成很多困惑...

关于javascript - Angular 不在表格行中显示数据。 ng-repeat 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34360532/

有关javascript - Angular 不在表格行中显示数据。 ng-repeat 不起作用的更多相关文章

  1. ruby-on-rails - Rails 编辑表单不显示嵌套项 - 2

    我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib

  2. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  3. ruby-on-rails - form_for 中不在模型中的自定义字段 - 2

    我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢

  4. ruby-on-rails - 使用 Sublime Text 3 突出显示 HTML 背景语法中的 ERB? - 2

    所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择

  5. ruby-on-rails - link_to 不显示任何 rails - 2

    我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article

  6. ruby-on-rails - 如何在 Rails View 上显示错误消息? - 2

    我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c

  7. ruby - 当使用::指定模块时,为什么 Ruby 不在更高范围内查找类? - 2

    我刚刚被困在这个问题上一段时间了。以这个基地为例:moduleTopclassTestendmoduleFooendend稍后,我可以通过这样做在Foo中定义扩展Test的类:moduleTopmoduleFooclassSomeTest但是,如果我尝试通过使用::指定模块来最小化缩进:moduleTop::FooclassFailure这失败了:NameError:uninitializedconstantTop::Foo::Test这是一个错误,还是仅仅是Ruby解析变量名的方式的逻辑结果? 最佳答案 Isthisabug,or

  8. ruby-on-rails - Prawn - 表格单元格内的链接 - 2

    我正在尝试用Prawn生成PDF。在我的PDF模板中,我有带单元格的表格。在其中一个单元格中,我有一个电子邮件地址:cell_email=pdf.make_cell(:content=>booking.user_email,:border_width=>0)我想让电子邮件链接到“mailto”链接。我知道我可以这样链接:pdf.formatted_text([{:text=>booking.user_email,:link=>"mailto:#{booking.user_email}"}])但是将这两行组合起来(将格式化文本作为内容)不起作用:cell_email=pdf.make_c

  9. ruby-on-rails - 复数 for fields_for has_many 关联未显示在 View 中 - 2

    目前,Itembelongs_toCompany和has_manyItemVariants。我正在尝试使用嵌套的fields_for通过Item表单添加ItemVariant字段,但是使用:item_variants不显示该表单。只有当我使用单数时才会显示。我检查了我的关联,它们似乎是正确的,这可能与嵌套在公司下的项目有关,还是我遗漏了其他东西?提前致谢。注意:下面的代码片段中省略了不相关的代码。编辑:不知道这是否相关,但我正在使用CanCan进行身份验证。routes.rbresources:companiesdoresources:itemsenditem.rbclassItemi

  10. ruby-on-rails - 在 Flash 警报 Rails 3 中显示错误消息 - 2

    如果我在模型中设置验证消息validates:name,:presence=>{:message=>'Thenamecantbeblank.'}我如何让该消息显示在闪光警报中,这是我迄今为止尝试过的方法defcreate@message=Message.new(params[:message])if@message.valid?ContactMailer.send_mail(@message).deliverredirect_to(root_path,:notice=>"Thanksforyourmessage,Iwillbeintouchsoon")elseflash[:error]

随机推荐