2015-12-06 2 views
2

Я новичок в Angularjs. Попытка сделать базовое приложение. Застрять.Vanilla AngularJs не загружается.

Я загрузил angularjs

<script type="text/javascript" 
src="https://code.angularjs.org/1.4.8/angular.min.js"></script> 

создал простую таблицу в HTML

<table ng-controller="CalculatorController"> 
    <thead> 
     <tr> 
      <th colspan="2"> 
       <h1>Calculator</h1> 
      </th> 
     </tr> 
    </thead> 
    <tr> 
     <td>First number</td> 
     <td><input ng-model="number1" type="number"></input></td> 

    </tr> 
    <tr> 
     <td>Second number</td> 
     <td><input ng-model="number2" type="number"></input></td> 
    </tr> 
    <tr> 

     <td colspan='2'><input type="button" ng-click="sum()" 
      value="Add"></input></td> 
    </tr> 
    <tr> 
     <td>Result</td> 
     <td>{{result}}</td> 
    </tr> 
</table> 

А потом добавил мой угловой модуль.

<script type="text/javascript"> 
    //Creates a new module called 'myApp' 
    angular.module('myApp', []); 

    // Load the app at document ready. 
    angular.element('document').ready(function() { 
     angular.bootstrap(document, [ 'myApp' ]); 
    }); 

Пока я еще не добавил свой контроллер, я ожидал, что страница будет правильно загружена. Однако при загрузке этой страницы в браузере я получаю следующую ошибку.

Error: [jqLite:nosel] http://errors.angularjs.org/1.4.8/jqLite/nosel 
Nangular.js:2737 
(anonymous function)Calculator.html:47 

Помогите пожалуйста.

ответ

2

jQLite не поддерживает запрос на основе селектора (если jQuery не включен перед AngularJS), в основном это требуется в элементе DOM. Вы должны иметь document без ' (котировки)

Код

angular.element(document).ready(function() { 
    angular.bootstrap(document, [ 'myApp' ]); 
}); 
Смежные вопросы