简体   繁体   English

不能达到角度方法

[英]Cant Reach the angular method

Hey guys for some reason my code below dosent work and gives me this result. 大家好,出于某些原因,下面的代码可以正常工作,并给出了此结果。 And when i click the save button, nothing alerts in the window? 当我单击“保存”按钮时,窗口中没有任何警报? I think somehow im not reaching the angular library but im not sure. 我认为某种程度上我没有到达角库,但我不确定。 Help would be appreciated! 帮助将不胜感激! Thankyou! 谢谢!

在此处输入图片说明

index.html: index.html:

<!DOCTYPE html>
<html lang="en">

<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.8/angular.js" data-semver="1.4.8"></script>
    <script src = "https://rawgit.com/nirus/Angular-Route-Injector/master/dist/routeInjector.js"></script>
    <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular-route.js"></script>
    <script type="text/javascript" src="main.js"></script>

    <script type="text/javascript" src="main.js"></script>
</head>
<body style="margin:20px">
<div>
    <label>Employee Name</label>
    <input type = "text" id="employeeName" ng-model="employeeName"><br />

    <label>Emploee Age</label>
    <input type = "text" id="employeeAge" ng-model="employeeAge"><br />
  </div>
  <div>
    <button class = "btn btn-default" ng-click = "saveEmployee()">
      Save <span class = "glyphicon glyphicon-ok">
    </button>

  </div>

  <div>
      Emplyee Name: {{employeeName}}<br />
      Employee Age: {{employeeAge}}
  </div>
 </body>

</html>

main.js: main.js:

function employeeCtrl($scope){
  $scope.employeeName = ""
  $scope.employeeAge = 0;
  $scope.saveEmployee = function(){
    alert('You have saved ' + $scope.employeeName)
  }
}

You need ng-app and ng-controller, this should work 您需要ng-app和ng-controller,这应该可以工作

<body ng-app="" ng-controller="employeeCtrl" style="margin:20px">
  <div>
    <label>Employee Name</label>
    <input type = "text" id="employeeName" ng-model="employeeName"><br />

    <label>Emploee Age</label>
    <input type = "text" id="employeeAge" ng-model="employeeAge"><br />
  </div>
  <div>
    <button class = "btn btn-default" ng-click = "saveEmployee()">
      Save <span class = "glyphicon glyphicon-ok">
     </button>

</div>

  <div>
      Emplyee Name: {{employeeName}}<br />
      Employee Age: {{employeeAge}}
  </div>
</body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM