2016-12-01 40 views
0

我是新來的角。以下代碼控制器未連接到模型。我只是得到初學者AngularJS無法獲取模型和控制器連接

我{{1 + 4}}

<!doctype html> 
    <html ng-app="myApp"> 
     <head> 
      <meta charset="utf-8"> 
      <title>AngularJS Email App</title> 
      <link href="css/style.css" rel="stylesheet"> 
     </head> 
     <body> 
     <script src="https://code.jquery.com/jquery-1.11.1.js"></script> 
     <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js"></script> 
     I am {{1+4}} 

     </script> 
    </body> 

+1

你應該寫'我是{{1 + 4}}'的身體,而不是在腳本。 –

+0

最後一個''不關閉任何東西,刪除它 –

+0

@BünyaminSarıgül,很好的捕獲,@ pob,只是刪除''最後 – Sravan

回答

0

你應該實現你的控制器,指令等,在您的腳本。像I am {{1+4}}這樣的網站內容應該位於視圖中,即腳本之外的代碼的正文部分。

0

<!DOCTYPE html> 
 

 
<html ng-app="begin"> 
 

 
    <head> 
 
    <meta charset="utf-8" /> 
 
    <title>AngularJS Plunker</title> 
 
    <script>document.write('<base href="' + document.location + '" />');</script> 
 
    <link rel="stylesheet" href="style.css" /> 
 
    <script data-require="[email protected]" src="https://code.angularjs.org/1.4.12/angular.js" data-semver="1.4.9"></script> 
 
    <script src="app.js"></script> 
 
    </head> 
 
<script> 
 
    var app = angular.module('begin',[]); 
 
     app.controller('BusContorller', function($scope){ 
 
     
 
     }); 
 

 
    </script> 
 

 
    
 
    <div ng-controller="BusContorller as bus"> 
 
     I am: {{1+4}} 
 
     </div> 
 
    </body> 
 

 
</html>

0

您鏈接NG-應用對myApp,您尚未創建該模塊又那麼它不會工作。如果你檢查你的開發者工具,你會看到一個錯誤。你得到一個錯誤的原因是因爲AngularJS沒有被引導到視圖,因爲它找不到myApp模塊。

你有兩個選擇:

  1. 刪除對myApp和只是不NG-應用=「」 因爲角度這將工作不會尋找一個特定的模塊來引導。

  2. 您可以通過添加下面的代碼添加另一個腳本標籤來創建該模塊。

    var myApp = angular.module("myApp", []);