[英]ng-init not working on initializing
我剛剛開始學習angular.js,但是ng-init
在我的代碼中不起作用。 我通過互聯網搜索,但找不到任何答案。
這是我的代碼,謝謝!
<!DOCTYPE html>
<html lang="en">
<head>
<title>ngClassifieds</title>
</head>
<body ng-app = "ngClassifieds" ng-init="message='hello, World!'">
<h1 ng-model="message">{{ message }}</h1>
<script src="node_modules/angular/angular.js"></script>
<script src="scripts/app.js"></script>
</body>
</html>
在您的app.js中添加以下代碼
var ngClassifieds=angular.module("ngClassifieds",[]);
我認為問題在於腳本加載
<head>
<title>ngClassifieds</title>
<script src="node_modules/angular/angular.js"></script>
<script src="scripts/app.js"></script>
</head>
在標題標簽中添加腳本
HTML代碼
<body ng-controller="DemoCtrl" ng-app="main" ng-init="data='welcome'">
{{data}}
</body>
腳本代碼
var app = angular.module('main', []);
app.controller('DemoCtrl', function ($scope) {
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.