2017-06-06 84 views
0

所以我试着用角JS我有简单角模块不能正常工作

<div ng-app="testApp" ng-controller="myCtrl"> {{firstName + " " + lastName}} </div> 在身体 一个小的测试应用程序,这

<script> 
     var testapp = angular.module("testApp",[]); 
     testapp.controller("myCtrl",function ($scope) { 
      $scope.firstName = "John"; 
      $scope.lastName = "Doe"; 
     }); 
    </script> 

就是它要关闭的。不过,我还是收到这样的:

enter image description here

我怎样才能得到它显示我想要的东西,这是“李四”?我知道我可能正在做一些简单的错误...

+1

在控制台中的任何错误下?也许Angular没有加载。 –

+0

@FrankModica是:错误:[$ controller:ctrlreg] http://errors.angularjs.org/1.6.4/$controller/ctrlreg?p0=myCtrl at angular.min.js:6 at angular.min。 (angular.min.js:76) at g(angular.min.js:68) at g(angular.min.js:61) at g(angular.min.js:62) ) at g(angular.min.js:62) at angular.min.js:61 at angular.min.js:22 at m。$ eval(angular.min.js:148) (anonymous) @ angular.min.js:123 – MattCom

+0

快速更正我的代码,但没有解决它,但testapp和testApp被命名为不同的,我从那里解决了。但结果仍然相同。 – MattCom

回答

0

您的代码在代码段编辑器中工作正常。 能否请您发布更多细节

请找工作实例

var testapp = angular.module("testApp",[]); 
 
     testapp.controller("myCtrl",function ($scope) { 
 
      $scope.firstName = "John"; 
 
      $scope.lastName = "Doe"; 
 
     });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="testApp" ng-controller="myCtrl"> 
 
    {{firstName + " " + lastName}} 
 
    </div>

+0

我在Webstorm中有完全相同的东西,它仍然不起作用。 – MattCom

+0

控制台中是否有任何错误。另请检查角度是否加载 – Haroon

0
//Create a seperate js file named module.js in which add your code as below 
var testapp = angular.module("testApp",[]); 
    testapp.controller("myCtrl",function ($scope) { 
     $scope.firstName = "John"; 
     $scope.lastName = "Doe"; 
    }); 

//then inject module.js file below the angular.min.js and please make 
//angular.min.js locally because it won't work when you will offline 
+0

希望这位运动员可以给你想法http://plnkr.co/edit/UkXKjmPFAWwoFGfC7WQs?p=info –