[英]ng-init not working on initializing
I have just started to learn angular.js but ng-init
is not working in my code. 我刚刚开始学习angular.js,但是
ng-init
在我的代码中不起作用。 I searched through internet but wasn't able to find any answer. 我通过互联网搜索,但找不到任何答案。
Here is my code thanks in advance !! 这是我的代码,谢谢!
<!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",[]);
I think the problem is with script loading 我认为问题在于脚本加载
<head>
<title>ngClassifieds</title>
<script src="node_modules/angular/angular.js"></script>
<script src="scripts/app.js"></script>
</head>
add your scripts in header tag 在标题标签中添加脚本
Html Code HTML代码
<body ng-controller="DemoCtrl" ng-app="main" ng-init="data='welcome'">
{{data}}
</body>
Script Code 脚本代码
var app = angular.module('main', []);
app.controller('DemoCtrl', function ($scope) {
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.