AngularJS ng控制器不工作 [英] AngularJS ng-controller not working

查看:142
本文介绍了AngularJS ng控制器不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚从 w3school 开始学习AngularJS。我正在尝试练习示例,他们在教程中提到过。每件事情都很好,但是当我来到AngularJS控制器时,它不能正常工作,因为在 w3schools试一试»。我将我的代码分成了这个小提琴示例
我的脚本如下所示:

  function personController($ scope){
$ scope.firstName = 约翰;
$ scope.lastName =Doe;
}

尽量帮助我,并为我提供一个很好的教程(或免费的pdf文件)。

解决方案

这是您的 校正小提琴



角度控制器定义必须看起来很好像这样:
$ b $ pre $ angular.module(app,[]).controller(personController,function($ scope) {
$ scope.firstName =John;
$ scope.lastName =Doe;
});

毫无疑问,是学习基础知识的最佳教程 Angular是 CodeSchool one!



希望这会有所帮助。


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";
}

Try to help me out and suggest me a good tutorial(or any free pdf file).

解决方案

This is your corrected fiddle.

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";
});

And, without doubt, the best tutorial ever for learning the basics of Angular is the CodeSchool one!

Hope this helps.

这篇关于AngularJS ng控制器不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆