0
我正在研究AngularJS主頁底部的本地化示例。AngularJS主頁 - 本地化示例
我正在查看頁面的源代碼,並嘗試完成演示向我展示的內容。
但是,我似乎無法啓動演示代碼。這讓我感到困惑的大部分線路是:
<span class="pull-right"
js-fiddle="tabs.html components.js beers.js" module="components"> ...
<div app-run="tabs.html" module="components-us" class="well"> ...
因爲我不認識app-run
或js-fiddle
是AngularJS語法(是嗎?)。無論如何,演示應用程序不會啓動。你能幫我看一下嗎?
這裏是我的代碼COPY從AngularJS主頁& PASTE並把index.html中:(管座基座和庫相應地改變你的目錄)
的index.html
<!doctype html>
<html ng-app>
<head>
<meta charset="utf-8">
<!-- ************IMPORTANT !! change this to your directory************ -->
<base href='http://localhost/angularjs/localization/' />
<link rel="stylesheet" href="../bootstrap/css/bootstrap.css">
<script src="../bootstrap/js/bootstrap.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
</head>
<body>
<div class=" row example">
<div class="span1 app-source" app-source="tabs.html components.js beers.js" annotate="tabs.annotation" module="components"></div>
<div class="span4">
<span hint></span>
<span class="pull-right" js-fiddle="tabs.html components.js beers.js" module="components"></span>
<div class="tabs-spacer"></div>
<h4>Locale: {{ 'US' }}</h4>
<div app-run="tabs.html" module="components-us" class="well"></div>
<div class="tabs-spacer"></div>
<h4>Locale: {{ 'SK' }}</h4>
<div app-run="tabs.html" module="components-sk" class="well"></div>
</div>
</div>
<script>
angular.module('components-us', ['components', 'ngLocal.us']);
angular.module('components-sk', ['components', 'ngLocal.sk']);
</script>
<script type="text/ng-template" id="tabs.html">
<tabs>
<pane title="Localization">
Date: {{ '2012-04-01' | date:'fullDate' }} <br>
Currency: {{ 123456 | currency }} <br>
Number: {{ 98765.4321 | number }} <br>
</pane>
<pane title="Pluralization">
<div ng-controller="BeerCounter">
<div ng-repeat="beerCount in beers">
<ng-pluralize count="beerCount" when="beerForms"></ng-pluralize>
</div>
</div>
</pane>
</tabs>
</script>
<script id="beers.js">
function BeerCounter($scope, $locale) {
$scope.beers = [0, 1, 2, 3, 4, 5, 6];
if ($locale.id == 'en-us') {
$scope.beerForms = {
0: 'no beers',
one: '{} beer',
other: '{} beers'
};
} else {
$scope.beerForms = {
0: 'žiadne pivo',
one: '{} pivo',
few: '{} pivá',
other: '{} pív'
};
}
}
</script>
<script id="components.js">
angular.module('components', []).
directive('tabs', function() {
return {
restrict: 'E',
transclude: true,
scope: {},
controller: function($scope, $element) {
var panes = $scope.panes = [];
$scope.select = function(pane) {
angular.forEach(panes, function(pane) {
pane.selected = false;
});
pane.selected = true;
}
this.addPane = function(pane) {
if (panes.length == 0) $scope.select(pane);
panes.push(pane);
}
},
template:
'<div class="tabbable">' +
'<ul class="nav nav-tabs">' +
'<li ng-repeat="pane in panes" ng-class="{active:pane.selected}">'+
'<a href="" ng-click="select(pane)">{{pane.title}}</a>' +
'</li>' +
'</ul>' +
'<div class="tab-content" ng-transclude></div>' +
'</div>',
replace: true
};
}).
directive('pane', function() {
return {
require: '^tabs',
restrict: 'E',
transclude: true,
scope: { title: '@' },
link: function(scope, element, attrs, tabsCtrl) {
tabsCtrl.addPane(scope);
},
template:
'<div class="tab-pane" ng-class="{active: selected}" ng-transclude>' +
'</div>',
replace: true
};
})
</script>
</body>
</html>
另外,哪裏有app-run
和js-fiddle
?我無法弄清楚它們是屬於AngularJS還是什麼的功能。
您是否試圖瞭解他們如何將此示例嵌入到主頁中,或者您只想查看本地化示例?如果是後者,只需點擊藍色的「編輯我」按鈕,你將在jsFiddle中獲得一個工作示例。 –