我是angularjs和ng-grid的新手......我目前正在通过一个简单的ng-grid示例,但我似乎无法让它工作。
这是我的HTML:
<!DOCTYPE html>
<html ng-app="myApp">
<head lang="en">
<meta charset="utf-8">
<title>Getting Started With ngGrid Example</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/ng-grid/2.0.11/ng-grid.css" data-semver="2.0.11" data-require="ng-grid@*" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js" data-semver="2.1.1" data-require="jquery@*"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.7/angular.js" data-semver="1.3.7" data-require="angular.js@*"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ng-grid/2.0.11/ng-grid.min.js" data-semver="2.0.11" data-require="ng-grid@*"></script>
<script src="js/controllers.js"></script>
</head>
<body ng-controller="MyCtrl">
<h1>{{title}}</h1>
<div class="gridStyle" ng-grid="gridOptions">
</div>
</body>
</html>
这是我的js:
'use strict';
var app = angular.module('myApp', ['ui.grid']);
app.controller('MyCtrl', function($scope) {
$scope.myData = [{name: "Moroni", age: 50},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34}];
$scope.gridOptions = { data: 'myData' };
$scope.title = "ng-grid example";
});
我还在Plunker中创建了一个我的问题示例:http://plnkr.co/edit/9fEF8sBAMhaMxWimLfTn?p=preview
谢谢!
珊
答案 0 :(得分:10)
您从找到的here获取此文档的文档错误地指出了以下内容
var app = angular.module('myApp', ['ui.grid']);
同一页面上的plunkr链接具有正确的
语法var app = angular.module('myApp', ['ngGrid']);
找到here。
答案 1 :(得分:2)
答案 2 :(得分:0)
试试这个肯定会有效。
这是我的HTML
<html ng-app="myApp">
<head lang="en">
<meta charset="utf-8">
<title>Getting Started With ngGrid Example</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="myscript.hs"></script>
<script type="text/javascript" src="angular.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ng-grid/2.0.11/ng-grid.min.js"></script>
</head>
<body ng-controller="MyCtrl">
<div class="gridStyle" ng-grid="gridOptions1" id="grid1"></div>
</body>
</html>
答案 3 :(得分:-1)
这是我的js。
<script>
var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
$scope.myData1 = [{name: "Moroni", age: 50, address:"bangalore", pin_code:44555},
{name: "Tiancum", age: 43, address:"mysore", pin_code:74034},
{name: "Jacob", age: 27, address:"bellary", pin_code:88394},
{name: "Nephi", age: 29, address:"ramanagara", pin_code:73883},
{name: "Enos", age: 34, address:"cpt", pin_code:34456}];
$scope.gridOptions1 = { data: 'myData1',
rowHeight: 25,
multiSelect:false,
enableRowSelection: true,
columnDefs: [
{
field: "name",
displayName: "Name",
width: '25%',
height: '50px',
},
{
field: "age",
displayName: "Age",
width: '25%',
height: '50px',
},
{
field: "address",
displayName: "Address",
width: '25%',
height: '50px'
},
{
field: "pin_code",
displayName: "PIN",
width: '25%',
height: '50px',
}
]};
});
</script>