2016-09-07 49 views

回答

0

對於Angularjs你不需要任何依賴。只是要包含angularjs庫(如jquery或任何其他庫)。已經看這裏:

<!doctype html> 
<html ng-app="todoApp"> 
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script> 
<script src="todo.js"></script> 
<link rel="stylesheet" href="todo.css"> 
</head> 
<body> 
<h2>Todo</h2> 
<div ng-controller="TodoListController as todoList"> 
    <span>{{todoList.remaining()}} of {{todoList.todos.length}} remaining</span> 
    [ <a href="" ng-click="todoList.archive()">archive</a> ] 
    <ul class="unstyled"> 
    <li ng-repeat="todo in todoList.todos"> 
     <label class="checkbox"> 
     <input type="checkbox" ng-model="todo.done"> 
     <span class="done-{{todo.done}}">{{todo.text}}</span> 
     </label> 
    </li> 
    </ul> 
    <form ng-submit="todoList.addTodo()"> 
    <input type="text" ng-model="todoList.todoText" size="30" 
      placeholder="add new todo here"> 
    <input class="btn-primary" type="submit" value="add"> 
    </form> 
</div> 
</body> 
</html> 

而且你app.js包含angularjs代碼:

angular.module('todoApp', []) 
.controller('TodoListController', function() { 
var todoList = this; 
todoList.todos = [ 
    {text:'learn angular', done:true}, 
    {text:'build an angular app', done:false}]; 

todoList.addTodo = function() { 
    todoList.todos.push({text:todoList.todoText, done:false}); 
    todoList.todoText = ''; 
}; 

todoList.remaining = function() { 
    var count = 0; 
    angular.forEach(todoList.todos, function(todo) { 
    count += todo.done ? 0 : 1; 
    }); 
    return count; 
}; 

todoList.archive = function() { 
    var oldTodos = todoList.todos; 
    todoList.todos = []; 
    angular.forEach(oldTodos, function(todo) { 
    if (!todo.done) todoList.todos.push(todo); 
    }); 
}; 
}); 

(我把這個例子從https://angularjs.org/),這樣就可以很容易理解。

但是,如果你想擴展與其他圖書館角度的功能,那麼你需要包括那些依賴,就像你說的答覆

+0

感謝拉胡爾。我想添加bootstrap和另一個dependency.it是手動添加或添加任何包管理器的最佳方式。 –

+0

@BharatDangar對我的例子,如果你想添加bootstrap然後使用:angular.module('todoApp',[])>>> angular.module('app',['ui.bootstrap'])我會建議閱讀此答案:http://stackoverflow.com/a/22422096/1960558。總是閱讀文檔:http://angular-ui.github.io/bootstrap/ –