Angular JS 控制器范围和私有函数和变量
Angular JS Controller scope and private functions and variables
我有一个问题,我几个月前在 angular 做了一个小应用程序,但为了扩展我对 angular 的了解,我决定添加一个功能和复杂性到我的代码。
所以不,我注入模块和控制器,我使用应用程序配置和 ng-route。
现在我有这样的东西:
var app = angular.module('myApp',['ngRoute']);
app.config(appConfig);
app.controller('TestController', ['$http', TestController])
function appConfig($routeProvider){
$routeProvider.when('/', {
templateUrl: './test.html',
controller: 'TestController',
controllerAs: 'my'
});
}
function TestController($http ) {
this.statusForm = 'Incompleto';
a();
}
function a(){
statusForm='Finalizado';
¿HOW DO I ACCES STATUSFORM TO CHANGE ITS VALUE IN TestController?
}
所以这就是我的问题,我如何在没有 $scope 的情况下从控制器内部调用的私有函数进行更改。
反正有没有参考 testcontroller 函数的范围?
我终于找到了问题的答案。我感到有点羞愧,因为答案有点简单。我应该比我更早更容易地弄清楚。
好的,我正在解释它,最初我有这个:
function TestController($http ) {
this.statusForm = 'Incompleto';
a();
}
function a(){
statusForm='Finalizado';
¿HOW DO I ACCES STATUSFORM TO CHANGE ITS VALUE IN TestController?
}
问题是 statusform 在函数 a 中不是可访问的,在它使用 $scope 之前它是可访问的。
function TestController($http ) {
this.statusForm = 'Incompleto';
a(**this**);
}
function a(**padre**){
**padre**.statusForm='Finalizado';
}
所以我以这种方式进行了更改(请参阅 ** 之间的更改),现在可以使用了。我以为我会有一些角度的方法来不将参数发送到函数 "a",但我没有找到任何方法。
任何方式这种方式都有效。
如果有人有同样的疑问,我希望这会有所帮助。你好。
我有一个问题,我几个月前在 angular 做了一个小应用程序,但为了扩展我对 angular 的了解,我决定添加一个功能和复杂性到我的代码。 所以不,我注入模块和控制器,我使用应用程序配置和 ng-route。 现在我有这样的东西:
var app = angular.module('myApp',['ngRoute']);
app.config(appConfig);
app.controller('TestController', ['$http', TestController])
function appConfig($routeProvider){
$routeProvider.when('/', {
templateUrl: './test.html',
controller: 'TestController',
controllerAs: 'my'
});
}
function TestController($http ) {
this.statusForm = 'Incompleto';
a();
}
function a(){
statusForm='Finalizado';
¿HOW DO I ACCES STATUSFORM TO CHANGE ITS VALUE IN TestController?
}
所以这就是我的问题,我如何在没有 $scope 的情况下从控制器内部调用的私有函数进行更改。 反正有没有参考 testcontroller 函数的范围?
我终于找到了问题的答案。我感到有点羞愧,因为答案有点简单。我应该比我更早更容易地弄清楚。 好的,我正在解释它,最初我有这个:
function TestController($http ) {
this.statusForm = 'Incompleto';
a();
}
function a(){
statusForm='Finalizado';
¿HOW DO I ACCES STATUSFORM TO CHANGE ITS VALUE IN TestController?
}
问题是 statusform 在函数 a 中不是可访问的,在它使用 $scope 之前它是可访问的。
function TestController($http ) {
this.statusForm = 'Incompleto';
a(**this**);
}
function a(**padre**){
**padre**.statusForm='Finalizado';
}
所以我以这种方式进行了更改(请参阅 ** 之间的更改),现在可以使用了。我以为我会有一些角度的方法来不将参数发送到函数 "a",但我没有找到任何方法。 任何方式这种方式都有效。 如果有人有同样的疑问,我希望这会有所帮助。你好。