无法加载角度视图

时间:2017-10-18 11:21:23

标签: angularjs

我有索引文件:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#" data-toggle="#article1">cart1</a>
<a href="#" data-toggle="#article2">cart 2</a>
<a href="#" data-toggle="#article3">cart 3</a>
<a href="#" data-toggle="#article4">cart 4</a>
<div class="wrapper">
  <article id="article1">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor</article>
  <article id="article2" class="active">sit amet, consectetur adipiscing elit, sed do eiusmod tempor</article>
  <article id="article3">consectetur adipiscing elit, sed do eiusmod tempor</article>
  <article id="article4">adipiscing elit, sed do eiusmod tempor</article>
</div>

我的控制器

<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="./js/jquery-1.9.1.js"></script>
<script src="./js/jquery-ui.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script>

<script src="./Controller/homingController.js"></script>
<link rel = "stylesheet" href = "./css/angular-material.min.css">
<link rel="stylesheet" href="./css/bootstrap-theme.min.css">
<link rel = "stylesheet" href = "./css/materialize.min.css">
<link href="./css/icon.css" rel="stylesheet">
<link rel ="stylesheet" href="./css/Main.css">
<title>Home Application</title>
</head>

<body ng-app="myApp">
<div class="navbar">
 <a href="#/home">Home</a>

<a href="#/monitor">about</a>
</div>

<div ng-view></div>

<script>


</script>
</body>
</html>

我的观点home.html

var app = angular.module('myApp', ['ngRoute']);
app.config(function ($routeProvider) {
$routeProvider.
when("/home", {
    templateUrl: "home.html"
    , controller: "homingController"
});
});

app.controller('homingController', function ($scope, $http) {
alert ("Hello");
var url = "workingURL"; /// changed function to a simple string message to 
test
$scope.message = "Hello Liberals";
});

它似乎都没有进入homingController并警告Hello。

当我调试它不去控制器时,它也不是加载视图。这里有什么我想念的吗?

1 个答案:

答案 0 :(得分:0)

Please refer following link: 

你需要分开js代码和HTML代码

https://jsfiddle.net/ok9he9b9/2/