Angular ui bootstrap 如果添加依赖关系手风琴不工作..?
Angular ui bootstrap accordion not working if add dependency..?
我已经从许多站点复制了 Angular ui 手风琴的示例,但是代码的 none 可以正常工作。当我使用该代码是 plunker 或任何类似的东西时,它可以工作但不能在我的电脑上工作。请帮助我。
这是我的html代码
<!DOCTYPE HTML>
<html lang="en-US" ng-app="myModule">
<head>
<meta charset="UTF-8">
<title>Accordion test</title>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.5/angular.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.4.0/ui-bootstrap-tpls.min.js"></script>
<script type="text/javascript" src="example.js"></script>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="AccordionDemoCtrl">
<label class="checkbox">
<input type="checkbox" ng-model="oneAtATime">
Open only one at a time
</label>
<accordion close-others="oneAtATime">
<accordion-group heading="Static Header">
This content is straight in the template.
</accordion-group>
<accordion-group heading="{{group.title}}" ng-repeat="group in groups">
{{group.content}}
</accordion-group>
<accordion-group heading="Dynamic Body Content">
<p>The body of the accordion group grows to fit the contents</p>
<button class="btn btn-small" ng-click="addItem()">Add Item</button>
<div ng-repeat="item in items">{{item}}</div>
</accordion-group>
</accordion>
</div>
</body>
</html>
这是js代码
angular.module('myModule', ['ui.bootstrap'])
function AccordionDemoCtrl($scope) {
$scope.oneAtATime = true;
console.log('bla');
$scope.groups = [
{
title: "Dynamic Group Header - 1",
content: "Dynamic Group Body - 1"
},
{
title: "Dynamic Group Header - 2",
content: "Dynamic Group Body - 2"
}
];
$scope.items = ['Item 1', 'Item 2', 'Item 3'];
$scope.addItem = function() {
var newItemNo = $scope.items.length + 1;
$scope.items.push('Item ' + newItemNo);
};
}
提前致谢..
您似乎没有将 AccordionDemoCtrl
控制器连接到 myModule
模块。你需要这样的东西:
angular.module('myModule').controller("AccordionDemoCtrl", AccordionDemoCtrl);
将该行放在 AccordionDemoCtrl
的当前定义下方(或上方),这应该会为您解决问题。
我已经从许多站点复制了 Angular ui 手风琴的示例,但是代码的 none 可以正常工作。当我使用该代码是 plunker 或任何类似的东西时,它可以工作但不能在我的电脑上工作。请帮助我。
这是我的html代码
<!DOCTYPE HTML>
<html lang="en-US" ng-app="myModule">
<head>
<meta charset="UTF-8">
<title>Accordion test</title>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.5/angular.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.4.0/ui-bootstrap-tpls.min.js"></script>
<script type="text/javascript" src="example.js"></script>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="AccordionDemoCtrl">
<label class="checkbox">
<input type="checkbox" ng-model="oneAtATime">
Open only one at a time
</label>
<accordion close-others="oneAtATime">
<accordion-group heading="Static Header">
This content is straight in the template.
</accordion-group>
<accordion-group heading="{{group.title}}" ng-repeat="group in groups">
{{group.content}}
</accordion-group>
<accordion-group heading="Dynamic Body Content">
<p>The body of the accordion group grows to fit the contents</p>
<button class="btn btn-small" ng-click="addItem()">Add Item</button>
<div ng-repeat="item in items">{{item}}</div>
</accordion-group>
</accordion>
</div>
</body>
</html>
这是js代码
angular.module('myModule', ['ui.bootstrap'])
function AccordionDemoCtrl($scope) {
$scope.oneAtATime = true;
console.log('bla');
$scope.groups = [
{
title: "Dynamic Group Header - 1",
content: "Dynamic Group Body - 1"
},
{
title: "Dynamic Group Header - 2",
content: "Dynamic Group Body - 2"
}
];
$scope.items = ['Item 1', 'Item 2', 'Item 3'];
$scope.addItem = function() {
var newItemNo = $scope.items.length + 1;
$scope.items.push('Item ' + newItemNo);
};
}
提前致谢..
您似乎没有将 AccordionDemoCtrl
控制器连接到 myModule
模块。你需要这样的东西:
angular.module('myModule').controller("AccordionDemoCtrl", AccordionDemoCtrl);
将该行放在 AccordionDemoCtrl
的当前定义下方(或上方),这应该会为您解决问题。