AngularJS ng-controller 不工作 [英] AngularJS ng-controller not working
问题描述
我刚刚从 w3schools 开始学习 AngularJS.我正在尝试练习他们在教程中提到的示例.一切正常,但是当我来到AngularJS 控制器"时,它在 w3schools 自己尝试».我已经将我的代码分叉到这个 小提琴示例.我的脚本如下所示:
I just now started learning on AngularJS from w3schools. I am trying to practice examples what ever they have mentioned in the tutorials. Every thing works fine but when i came to "AngularJS Controllers" it is not working properly as working well in w3schools Try it Yourself ». I ve forked my code into this fiddle example. My script looks like this:
function personController($scope) {
$scope.firstName= "John";
$scope.lastName= "Doe";
}
试着帮助我并向我推荐一个好的教程(或任何免费的 pdf 文件).
Try to help me out and suggest me a good tutorial(or any free pdf file).
推荐答案
This is your 更正小提琴.
This is your corrected fiddle.
对于 angular 来说,控制器定义必须看起来像这样是一个很好的做法:
It is a good practice for angular that the controller definition must look something like this:
angular.module("app", []).controller("personController", function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
});
毫无疑问,学习 Angular 的基础最好的教程是CodeSchool 一个!
And, without doubt, the best tutorial ever for learning the basics of Angular is the CodeSchool one!
希望这会有所帮助.
这篇关于AngularJS ng-controller 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!