Reputation: 683
I'm very new to angular js and following is my code
<script type="text/javascript" src="node_modules/angular/angular.min.js"></script>
<script type="text/javascript">
(function(angular){
var testAngular = angular.module('testAngular');
testAngular.controller = ("name_controller", function($scope) {console.log("hello");
$scope.name = {
firstName: "null",
lastName: "null",
setName: function(fname, lname) {
if(fname.trim != "") {
this.firstName = fname;
}
if(lname.trim()!="") {
this.lastName = lname;
}
},
getName: function() {
var name_object = $scope.name;
return name_object.firstName+" "+name_object.lastName;
}
};
});
})(window.angular);
</script>
<div ng-app="testAngular" ng-controller="name_controller">
Enter first name: <input type="text" ng-model="name.firstName"><br><br>
Enter last name: <input type="text" ng-model="name.lastName"><br>
<br>
You are entering: {{ name.firstName }}
</div>
Now when I'm trying to run this code I'm getting 2 errors in console as
[$injector:nomod]
and
[$injector:modulerr]
Any idea why exactly this is happening. Some post says I need to include the route module but I'm not using routing any where in my code.
Upvotes: 0
Views: 39
Reputation: 463
Try to change:
testAngular.controller = ("name_controller", function($scope) {
to
testAngular.controller("name_controller", function($scope) {
Upvotes: 1