Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 此应用程序中的视图中未显示控制器属性_Javascript_Html_Angularjs - Fatal编程技术网

Javascript 此应用程序中的视图中未显示控制器属性

Javascript 此应用程序中的视图中未显示控制器属性,javascript,html,angularjs,Javascript,Html,Angularjs,下面是我的AngularJS应用程序中的aap.js var app = angular.module('gallery',[]); (function(){ app.controller('GalleryController',function(){ this.tab = true; }); })(); 和gallery.html是: <html ng-app="gallery"> <head> <link

下面是我的AngularJS应用程序中的
aap.js

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

(function(){

    app.controller('GalleryController',function(){
        this.tab = true;
    }); 
})();
和gallery.html
是:

<html ng-app="gallery">

<head>    
    <link rel="stylesheet" type="text/css" href="bootstrap.min.css">
    <script type="text/javascript" src="angular.js"></script>
    <script type="text/javascript" src="app.js"></script>
    <link rel="shortcut icon" href="">    
</head>
<body ng-contoller="GalleryController as g">
 <section >
 <ul>
     <li><img ng-click="tab=1" src="images/gem-01.jpg" height="100" /></li>
 </ul>
     <h1>{{g.tab}}</h1>
</section>
</body>
</html>

{{g.tab}}

g.tab
,这是控制器的属性,未显示在视图中。为什么会这样?

再次编辑:我错过了阅读您的文章。您使用的是
this
关键字correct,但是当您单击图像时,
tab
属性没有显示,因为
ng click
正在使用
tab
而不是
g.tab
。请参见更新的小提琴:

您不能在控制器中像那样使用
this
关键字。控制器方法的上下文不是您的作用域。是的,你可以看到编辑

您可以在服务中使用该语法,但不能在控制器中使用,相反,您的范围将与其他服务、工厂等一起注入

应该是这样

app.controller('GalleryController',function($scope){
    $scope.tab = true;
}); 
最有可能是杀伤力过大,但还是增加了小提琴来演示:

编辑:这可以通过使用
This
关键字来实现。我不知道这个,每天都要学习新的东西。这是通过在
ng控制器中使用
as
操作符来实现的

请参阅更新的小提琴: 我在以下文件中找到它:

我的理解是,
as
操作符将你的作用域绑定到你视图中的一个属性,你通过了
testas myScope
意味着绑定你视图中
test
属性的
这个
关键字


希望这是有意义的。

再次编辑:我错过了阅读您的文章。您使用的是
this
关键字correct,但是当您单击图像时,
tab
属性没有显示,因为
ng click
正在使用
tab
而不是
g.tab
。请参见更新的小提琴:

您不能在控制器中像那样使用
this
关键字。控制器方法的上下文不是您的作用域。是的,你可以看到编辑

您可以在服务中使用该语法,但不能在控制器中使用,相反,您的范围将与其他服务、工厂等一起注入

应该是这样

app.controller('GalleryController',function($scope){
    $scope.tab = true;
}); 
最有可能是杀伤力过大,但还是增加了小提琴来演示:

编辑:这可以通过使用
This
关键字来实现。我不知道这个,每天都要学习新的东西。这是通过在
ng控制器中使用
as
操作符来实现的

请参阅更新的小提琴: 我在以下文件中找到它:

我的理解是,
as
操作符将你的作用域绑定到你视图中的一个属性,你通过了
testas myScope
意味着绑定你视图中
test
属性的
这个
关键字


希望这是有意义的。

再次编辑:我错过了阅读您的文章。您使用的是
this
关键字correct,但是当您单击图像时,
tab
属性没有显示,因为
ng click
正在使用
tab
而不是
g.tab
。请参见更新的小提琴:

您不能在控制器中像那样使用
this
关键字。控制器方法的上下文不是您的作用域。是的,你可以看到编辑

您可以在服务中使用该语法,但不能在控制器中使用,相反,您的范围将与其他服务、工厂等一起注入

应该是这样

app.controller('GalleryController',function($scope){
    $scope.tab = true;
}); 
最有可能是杀伤力过大,但还是增加了小提琴来演示:

编辑:这可以通过使用
This
关键字来实现。我不知道这个,每天都要学习新的东西。这是通过在
ng控制器中使用
as
操作符来实现的

请参阅更新的小提琴: 我在以下文件中找到它:

我的理解是,
as
操作符将你的作用域绑定到你视图中的一个属性,你通过了
testas myScope
意味着绑定你视图中
test
属性的
这个
关键字


希望这是有意义的。

再次编辑:我错过了阅读您的文章。您使用的是
this
关键字correct,但是当您单击图像时,
tab
属性没有显示,因为
ng click
正在使用
tab
而不是
g.tab
。请参见更新的小提琴:

您不能在控制器中像那样使用
this
关键字。控制器方法的上下文不是您的作用域。是的,你可以看到编辑

您可以在服务中使用该语法,但不能在控制器中使用,相反,您的范围将与其他服务、工厂等一起注入

应该是这样

app.controller('GalleryController',function($scope){
    $scope.tab = true;
}); 
最有可能是杀伤力过大,但还是增加了小提琴来演示:

编辑:这可以通过使用
This
关键字来实现。我不知道这个,每天都要学习新的东西。这是通过在
ng控制器中使用
as
操作符来实现的

请参阅更新的小提琴: 我在以下文件中找到它:

我的理解是,
as
操作符将你的作用域绑定到你视图中的一个属性,你通过了
testas myScope
意味着绑定你视图中
test
属性的
这个
关键字


希望这是有意义的。

将所有值绑定到$scope

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

    (function(){

        app.controller('GalleryController',function($scope){
            $scope.tab = true;
        }); 
    })();
您的HTML看起来像

<html ng-app="gallery">

<head>    
    <link rel="stylesheet" type="text/css" href="bootstrap.min.css">
    <script type="text/javascript" src="angular.js"></script>
    <script type="text/javascript" src="app.js"></script>
    <link rel="shortcut icon" href="">    
</head>
<body ng-contoller="GalleryController">
 <section >
 <ul>
     <li><img ng-click="tab=1" src="images/gem-01.jpg" height="100" /></li>
 </ul>
     <h1>{{tab}}</h1>
</section>
</body>
</html>

{{tab}}
将所有值绑定到$scope

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

    (function(){

        app.controller('GalleryController',function($scope){
            $scope.tab = true;
        }); 
    })();
您的HTML看起来像

<html ng-app="gallery">

<head>    
    <link rel="stylesheet" type="text/css" href="bootstrap.min.css">
    <script type="text/javascript" src="angular.js"></script>
    <script type="text/javascript" src="app.js"></script>
    <link rel="shortcut icon" href="">    
</head>
<body ng-contoller="GalleryController">
 <section >
 <ul>
     <li><img ng-click="tab=1" src="images/gem-01.jpg" height="100" /></li>
 </ul>
     <h1>{{tab}}</h1>
</section>
</body>
</html>

{{tab}}
将所有值绑定到$scope

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

    (function(){

        app.controller('GalleryController',function($scope){
            $scope.tab = true;
        }); 
    })();
您的HTML看起来像

<html ng-app="gallery">

<head>    
    <link rel="stylesheet" type="text/css" href="bootstrap.min.css">
    <script type="text/javascript" src="angular.js"></script>
    <script type="text/javascript" src="app.js"></script>
    <link rel="shortcut icon" href="">    
</head>
<body ng-contoller="GalleryController">
 <section >
 <ul>
     <li><img ng-click="tab=1" src="images/gem-01.jpg" height="100" /></li>
 </ul>
     <h1>{{tab}}</h1>
</section>
</body>
</html>

{{tab}}
将所有值绑定到$scope