角度js不顯示任何東西,即使是簡單的表達式。我正試圖執行下面的代碼,但沒有希望。誰能幫我嗎。角度Js不能正常工作
以下代碼是用於視圖中顯示。
`<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script type="text/javascript" src="/../../Scripts/angularsample.js"></script>
</head>
<body ng-app="spiceApp">
<div>
<div ng-controller="SpicyController">
<p> lets try some code by using service </p>
<input ng-init="message='Girish'" ng-model="message" />
<button ng-click="notify(message);">Notify{{1+2}}</button>
<p>alert will display only by clicking three times.</p>
</div>
<div ng-controller="List">
<button ng-click="bringList()">getList</button>
<table>
<tr ng-repeat="app in appslist">
<td>
{{app.Name}}
</td>
</tr>
</table>
</div>
</div>
</body>
</html>`
js代碼
var myApp = angular.module('spiceApp', []);
myApp.controller('SpicyController', ['$scope', '$http', 'userService', , function ($scope, $http, userService) {
//below code is using sservice
$scope.notify = function (msg) {
userService(msg);
};
}]);
myApp.controller('List', ['$scope', 'getList', function ($scope, getList) {
$scope.bringList = function() {
getList.getAppsList().then(function (list) {
$scope.appslist = list;
});
};
}]);
myApp.factory('getList', ['$http',function ($http) {
//this code for getting list from controller.
return getList.getAppsList=function(){
$http({
method: 'GET',
url: 'Home/GetAppsList'
})
.success(function (response) {
return response.data;
}, function (error) {
console.log(error);
});
}
}]);
myApp.factory('userService', ['$window', function (win) {
var msgs = [];
return function (msg) {
msgs.push(msg);
if (msgs.length == 3) {
win.alert(msgs.join('\n'));
msgs = [];
}
};
}]);`
,請告訴我,我錯了。沒有任何工作。表達式在ouptut中顯示爲{{1 + 2}}。
你有沒有在控制檯中的錯誤? – Alteyss
在控制檯現在我得到的錯誤是: –
的ReferenceError:的GetList不是在對象定義 。在angular.js中Object.invoke(angular.js:4708) $ get(angular.js:4547) (Object.invoke(angular.js:4708) )在Object.invoke(angular.js:4708) :4507 在d(angular.js:4654) 在E(angular.js:4678) 在Object.invoke(angular.js:4700) 在P.instance(angular.js:10177) 以n( angular.js:9096) (匿名)@ angular.js:13642 –