1、错误描述
- angular.min.js:118 Error: [ng:areq] http://errors.angularjs.org/1.5.8/ng/areq?p0=username&p1=not%20a%20function%2C%20got%20undefined
- at Error (native)
- at http://127.0.0.1:8020/AngularJS/js/angular.min.js:6:412
- at sb (http://127.0.0.1:8020/AngularJS/js/angular.min.js:23:18)
- at Pa (http://127.0.0.1:8020/AngularJS/js/angular.min.js:23:105)
- at http://127.0.0.1:8020/AngularJS/js/angular.min.js:89:310
- at ag (http://127.0.0.1:8020/AngularJS/js/angular.min.js:72:419)
- at p (http://127.0.0.1:8020/AngularJS/js/angular.min.js:64:262)
- at g (http://127.0.0.1:8020/AngularJS/js/angular.min.js:58:481)
- at g (http://127.0.0.1:8020/AngularJS/js/angular.min.js:58:498)
- at g (http://127.0.0.1:8020/AngularJS/js/angular.min.js:58:498)
- <!DOCTYPE html>
- <html ng-app>
- <head>
- <meta charset="UTF-8">
- <title></title>
- <script type="text/javascript" src="../js/angular.min.js" ></script>
- </head>
- <body>
- <div ng-controller="username">
- <input type="text" id="inp" ng-model="user.name">
- <div>{{user.name}}</div>
- </div>
- <script>
- function username($scope)
- {
- $scope.user = {name:"杰西卡"};
- }
- </script>
- </body>
- </html>
3、解决办法
- <!DOCTYPE html>
- <html ng-app="userApp">
- <head>
- <meta charset="UTF-8">
- <title></title>
- <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
- <script>
- var app = angular.module("userApp",[]);
- app.controller("username",function($scope){
- $scope.user = {name:"杰西卡"}
- });
- </script>
- </head>
- <body>
- <div ng-controller="username">
- <input type="text" id="inp" ng-model="user.name">
- <div>{{user.name}}</div>
- </div>
- </body>
- </html>