簡體   English   中英

Angular.js中的配置模塊

[英]config module in Angular.js

我是angujar.js的新手,我想開發一個簡單的應用程序,該應用程序使用一些HTML文件來更改內容,例如本示例

我的配置錯了嗎? 我還需要做什么?

的index.html

<html ng-app="main">
<head>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
</head>

<body>
    Some title
    <div ng-view></div>
</body>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js">
<script src="js/main.js"></script> <!-- app -->

</html>

main.js

var mymain = angular.module('main',[]);

mymain .config(  function($routeProvider) {
    $routeProvider.
      when('/', {
        templateUrl: 'otherfile.html',
        controller: 'F'
      }).
      otherwise({
        redirectTo: '/'
      });
  });

mymain.controller('F', function($scope) { 
    alert("here");    
});

otherfile.html

<span>Something else...</span>

提前致謝。

編輯

我是否必須在服務器(至少是localhost)上安裝angular.js? 我的route代碼在這里有效,但是當我僅使用瀏覽器打開文件時不起作用。

路由器不是核心angular.js文件的一部分。 它是一個單獨的模塊,必須在您的主模塊依賴項中聲明。 它也位於單獨的JS文件中,必須將其添加到index.html文件中,如文檔所述

JB Nizet是對的,我需要

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular-resource.min.js"></script>

但是我也需要

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular-route.min.js"></script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM