I've been reading the angularjs tutorials on tutorialspoint.com and I've been testing things that I learn on jsfiddle. The first few things I tried worked, like ng-model
and ng-bind
. But this was all with an empty ng-app
( ng-app=""
).
However, now I'm trying to make an app and a controller, but its not working. Heres the fiddle
How do I fix this code? I've done exactly as the tutorial says. I just noticed when inspecting the page I get the following error:
Error: [$injector:modulerr] Failed to instantiate module myapp due to: [$injector:nomod] Module 'myapp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
<div ng-app="myapp" ng-controller="appController">
<div>
<span>First</span>
<input type='text' ng-model="person.firstname"/>
<span ng-bind="person.firstname"></span>
</div>
<div>
<span>Last</span>
<input type='text' ng-model="person.lastname"/>
<span ng-bind="person.lastname"></span>
</div>
<div> {{ person.fullname() }} </div>
</div>
var myapp = angular.module("myapp", []);
myapp.controller('appController', function($scope) {
$scope.person = {
firstname: "one",
lastname: "two",
fullname: function() {
var personobject;
personobject = $scope.person;
return personobject.firstname + " " + personobject.lastname;
}
};
});
在框架和设置下,将onLoad上的内容更改为无内包 - <head>
或不包装 - <body>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.