相关疑难解决方法(0)

如何让lodash与Angular JS一起使用?

我正在尝试使用lodash在ng-repeat指令中使用它,这样:

<div ng-controller="GridController" ng-repeat="n in _.range(5)">
    <div>Hello {{n}}</div>
</div>
Run Code Online (Sandbox Code Playgroud)

存在GridController:

IndexModule.controller('GridController', function () {

this._ = _

})
Run Code Online (Sandbox Code Playgroud)

但是没有工作,所以没有重复.如果我改变指令ng-repeat="i in [1,2,3,4,5]"它将工作.

lodash已经包含<script><header>之前angular.我怎样才能使它工作?

javascript angularjs lodash

65
推荐指数
3
解决办法
7万
查看次数

Angularjs - ng-disabled无法正常工作

我试图input在用户选择文件后禁用文件标记.

HTML:

<div ng-controller='firstController'>
    <div ng-controller='secondController'>
      <input type="file" name="file" upload class="theFileInput" ng-disabled="fileInMemory">
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

JS,第一控制器:

$scope.fileInMemory = false; // tracks if user selected a file for upload, but didn't upload it
$rootScope.$on('fileAdded', function () {
     $scope.fileInMemory = true;
     console.log($scope.fileInMemory);
});
Run Code Online (Sandbox Code Playgroud)

upload 是一个指令.

在页面加载时,ng-disabled具有false应该fileInMemory更改时,input标记仍未被禁用.console.log表明价值fileInMemory正在发生变化.

到目前为止我尝试了什么

<input type="file" name="file" class="theFileInput" ng-disabled="'fileInMemory'">
Run Code Online (Sandbox Code Playgroud)

只是禁用该字段,什么时候fileInMemory是假的.

<input type="file" name="file" class="theFileInput" ng-disabled="fileInMemory == 'true'">
Run Code Online (Sandbox Code Playgroud)

不行.

<input type="file" name="file" class="theFileInput" ng-disabled="{{fileInMemory}}">
Run Code Online (Sandbox Code Playgroud)

仍然无法正常工作. …

html javascript angularjs

9
推荐指数
1
解决办法
8824
查看次数

使用"controllerAs"属性的原因是什么?

我用谷歌搜索,但我没有找到我的问题的适当答案,我是angularJS的新手我正在研究我的angularJS教程.

我有这个angularJS行:

.state('index',{
url:"/",
templateUrl:"views/index.html",
controller:"IndexCtrl",
controllerAs:"index"
})
Run Code Online (Sandbox Code Playgroud)

使用controllerAs属性的原因是什么?

angularjs

8
推荐指数
1
解决办法
4943
查看次数

将 $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
查看次数

JavaScript | 角 | 控制器作为语法:不能使用`this`

不能使用 ControllerAs this

任何人都可以向我解释以下场景吗?

作品

ng-controller="Parent as thus"
Run Code Online (Sandbox Code Playgroud)

休息时间

ng-controller="Parent as this"
Run Code Online (Sandbox Code Playgroud)

使它成为关键字的单个字母 - 我想要 - 破坏了森林。

为什么是这样?

PS 我知道这个vm约定,但我发现它干扰了控制器/视图模型的可移植性。

javascript this angularjs angularjs-controlleras

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