定义的两个控制器之一 (AboutCtrl) 按预期工作。默认控制器 TransactionCtrl 与正确的局部视图配对,但没有发生任何 angularjs 魔术。例如,我有一个未解析的简单表达式 1 + 2 = {{ 1+2}}(显示为书面形式)。
这是应用程序定义:
angular.module('pennyWatch', ['ui.bootstrap'])
.config(['$routeProvider', function ($routeProvider) {
return $routeProvider
.when('/', { title: 'Transactions', templateUrl: 'partials/transaction.view.html', controller: TransactionCtrl })
.when('/about', { title: 'About', templateUrl: 'partials/about.view.html', controller: AboutCtrl })
.when('/transaction', { title: 'Transactions', templateUrl: 'partials/transaction.view.html', controller: TransactionCtrl })
.otherwise({ redirectTo: '/' });
}])
这是控制器。我可以打断点,AboutCtrl
但不能打另一个。我TransactionCtrl.$inject
最近添加了看看是否有帮助,但没有区别:
function TransactionCtrl($scope, $location, logger, ngGrid) {
logger.log("in TransactionCtrl");
$scope.transactionList =
[
{ TransactionID: 1, Title: "TuElectric", Category: "Expense", Amount: "$ 76.80", Date: "Jan 1" },
{ TransactionID: 2, Title: "QT", Category: "Expense", Amount: "$ 62.38", Date: "Jan 1" },
{ TransactionID: 3, Title: "Kroger", Category: "Expense", Amount: "$ 123.67", Date: "Jan 3" },
{ TransactionID: 4, Title: "All State", Category: "Expense", Amount: "$ 248.17", Date: "Jan 3" },
{ TransactionID: 5, Title: "Credit Union", Category: "Income", Amount: "$1,897.00", Date: "Jan 4" }
];
$scope.error = "";
$scope.gridOptions = {
data: "transactionList"
//, showGroupPanel: true
};
}
TransactionCtrl.$inject = ['$scope', '$location', 'logger', 'ngGrid'];
function AboutCtrl($scope, logger) {
$scope.logEntries = logger.logEntries;
}
部分观点:
<!-- Transaction page partial view -->
<div style="position: absolute; top: 20px; left:2em;">
<a href="#/about" class="pageLink">About</a>
</div>
<p class="error" data-ng-show="error.length">{{error}}</p>
<br/>
<article>
<header>
<h2>Transaction List</h2>
</header>
<p>(trnx view) 1 + 2 = {{ 1 + 2 }}</p>
<ul id="fauxTable">
<li>
<p><span>Title</span><span>Category</span><span>Amount</span><span>Date</span></p>
</li>
<li data-ng-repeat="item in transactionList">
<p><span>{{item.Title}}</span><span>{{item.Category}}</span><span>{{item.Amount}}</span><span>{{item.Date}}</span></p>
</li>
</ul>
</article>
<article>
<h2>Transaction List (ngGrid)</h2>
<div class="gridStyle" ng-grid="gridOptions">
</div>
</article>
谢谢!