相关疑难解决方法(0)

将 $scope 替换为“'controller' as”语法

我正在关注这个 AngularJS+ASP.NET 教程,他们使用了$scope,但我试图用新语法替换过时的用法controller,如这个问题中所述:“AngularJs“控制器作为”语法 - 澄清?”

我所做的目前不起作用。页面在函数$http.get内部调用nextQuestion(),但视图保持不变,只有标题"loading question..."


我的代码:

JS http://pastebin.com/RfngRuZD

var app = angular.module('QuizApp', [])

app.controller('QuizCtrl', ['$http', function ($http) {
    this.answered = false;
    this.title = "loading question...";
    this.options = [];
    this.correctAnswer = false;
    this.working = false;

    this.answer = function () {
        return this.correctAnswer ? 'correct' : 'incorrect';
    };

    // GET
    this.nextQuestion = function () {
        this.working = true;
        this.answered = false;
        this.title = "loading question...";
        this.options = …
Run Code Online (Sandbox Code Playgroud)

javascript asp.net controller angularjs angularjs-scope

2
推荐指数
1
解决办法
3190
查看次数