在我的MVC程序中,簡單的角度值控制器值不具有約束力。 我的代碼如下:AngularJS - 控制器值不綁定
_Layout.cshtml
<body data-ng-app="ShoppingCartApp">
<div class="container body-content">
@RenderBody()
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/Scripts/angular.js")
@Scripts.Render("~/Scripts/Custom/App.js")
@Scripts.Render("~/Scripts/Custom/ShoppingCartController.js")
@RenderSection("scripts", required: false)
<hr />
</div>
</body>
App.js
var app = angular.module('ShoppingCartApp', []);
ShoppingCartController.js
app.controller('ShoppingCartController', function ShoppingCartController($scope, $http) {
$scope.ShoppingCartObj.products = [];
$scope.test = "ABC";
// On load events
// $scope.loadValues();
});
我的HTML代碼如下:
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script></script>
<h2>Index</h2>
Total {{2+2}} // This value workd FINE
<div ng-controller="ShoppingCartController">
<div class="row">
<div class="nav navbar-nav navbar-left">
<h3>Total {{2+2}}</h3> // Not working THIS
</div>
<h1>{{test}}</h1> // Not working THIS
</div>
</div>
當我嘗試在內部控制它不工作控制器或訪問指令來訪問值。我在這裏想念什麼?
我改變它這樣。但即使不起作用 – DevT
控制檯中與注入或其他錯誤有關的任何錯誤? – Developer
是的,有..不能設置屬性'產品'的未定義 – DevT