【问题标题】:Angularjs directive doesn't seems to be working could not able to resolve ngshowAngularjs 指令似乎不起作用无法解析 ngshow
【发布时间】:2020-07-07 03:09:51
【问题描述】:

大家好,我是 angularJS 的入门级程序员,我尝试使用 ng-show,但我不知道为什么它不起作用。我使用了最新版本的 Angular js-1.7.9。

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Index Page</title>
    
    
</head>
<body >
<div ng-app="myApp">
    Enter Your Name: <input type="text" ng-model="firstName">
    <br>
    <b>{{firstName}}</b>
    <div ng-controller="ShowController">
        <button ng-click="showParagaph()">Click Me</button>
        <p ng-show="visible">Hello world</p>



    </div>


</div>

<script src="./js/angular.js"></script> 
 
<script>
var app = angular.module('myApp', []);
app.controller('ShowController', function($scope) {
  
    $scope.visible=true;
    $scope.showParagraph = function() {
        $scope.visible=false;
    };
});



</script>
     
     

  
</body>
</html>
我尝试了许多可能的解决方案,但无法解决错误。提前致谢。

【问题讨论】:

    标签: angularjs angularjs-scope frontend angularjs-ng-show


    【解决方案1】:

    修正错字:

    ̶<̶b̶u̶t̶t̶o̶n̶ ̶n̶g̶-̶c̶l̶i̶c̶k̶=̶"̶s̶h̶o̶w̶P̶a̶r̶a̶g̶a̶p̶h̶(̶)̶"̶>̶C̶l̶i̶c̶k̶ ̶M̶e̶<̶/̶b̶u̶t̶t̶o̶n̶>̶ 
    <button ng-click="showParagraph()">Click Me</button>
    

    var app = angular.module('myApp', []);
    app.controller('ShowController', function($scope) {  
        $scope.visible=true;
        $scope.showParagraph = function() {
            $scope.visible=false;
        };
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
    <body ng-app="myApp">
        Enter Your Name: <input type="text" ng-model="firstName">
        <br>
        <b>{{firstName}}</b>
        <div ng-controller="ShowController">
            <button ng-click="showParagraph()">Click Me</button>
            <p ng-show="visible">Hello world</p>
        </div>
    </body>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-07
      • 2011-03-13
      • 1970-01-01
      相关资源
      最近更新 更多