我是angularjs的新手。我正在尝试创建一个简单的控制器,但我不能。 真的需要帮助。
<html data-ng-app="ionicApp" >
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>Ionic Template</title>
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script>
function SimpleController($scope){
$scope.customers=[
{name:'Djo', city:'johannesburg'},
{name:'tri',city:'vaal'},
{name:'stone',city:'pretoria'},
{name:'loick',city:'durban'}
];
}
</script>
<body >
<div class="container" ng-controllers="SimpleController">
<ul >
<!-- we are accessing thescope -->
Name: <input type="text" data-ng-model="name" /> {{ name}}
<li ng-repeat="cust in customers"> {{ custt.name}} - {{cust.city}} </li>
</ul>
</div>
</body>
</html>
答案 0 :(得分:1)
在angularjs 1.3 +
中禁用了全局控制器<html ng-app="ionicApp">
<body>
<div ng-controller="SimpleController">
</div>
</body>
<script>
angular.module("ionicApp",[])
.controller("SimpleController", [$scope, function($scope){
// your code here
}])
</script>
答案 1 :(得分:0)
解决!这很简单:
而不是
<script>
angular.module("ionicApp",[])
.controller("SimpleController", [$scope, function(){
// my code here
}])
</script>
我刚刚将$ scope作为函数
中的参数传递<script>
angular.module("ionicApp",[])
.controller("SimpleController",function($scope){
// my code here
})
</script>
谢谢你的帮助