javascript - Why is my Angular.js $routeProvider doing nothing? - Stack Overflow

I'm learning Angular.js right now by following along with the videos at Egghead.io. I'm at th

I'm learning Angular.js right now by following along with the videos at Egghead.io. I'm at the $routeProvider video, and my app isn't routing at all.

It's ultra basic, here's the script (app.js):

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

// routes
app.config(function ($routeProvider) {
    $routeProvider.when('/pizza', { template: 'Yum!!' });
});

app.controller('FirstCtrl', function ($scope) {
    $scope.data = { message: "Hello" };
});

And the html:

<div ng-app="myApp">
    <div ng-controller="FirstCtrl">
    {{data.message + " world"}}
    </div>
</div>

<script type="text/javascript" src="//cdnjs.cloudflare/ajax/libs/angular.js/1.1.3/angular.min.js"></script>
<script src="app.js"></script>

From my understanding, http://host/#/pizza should simply show "Yum!!" since I'm passing a string in the template. It doesn't appear to do anything though, I still get "Hello world" as evaluated by the FirstCtrl.

Why isn't the $routeProvider doing anything in my app?

I'm learning Angular.js right now by following along with the videos at Egghead.io. I'm at the $routeProvider video, and my app isn't routing at all.

It's ultra basic, here's the script (app.js):

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

// routes
app.config(function ($routeProvider) {
    $routeProvider.when('/pizza', { template: 'Yum!!' });
});

app.controller('FirstCtrl', function ($scope) {
    $scope.data = { message: "Hello" };
});

And the html:

<div ng-app="myApp">
    <div ng-controller="FirstCtrl">
    {{data.message + " world"}}
    </div>
</div>

<script type="text/javascript" src="//cdnjs.cloudflare./ajax/libs/angular.js/1.1.3/angular.min.js"></script>
<script src="app.js"></script>

From my understanding, http://host/#/pizza should simply show "Yum!!" since I'm passing a string in the template. It doesn't appear to do anything though, I still get "Hello world" as evaluated by the FirstCtrl.

Why isn't the $routeProvider doing anything in my app?

Share Improve this question edited Jun 26, 2017 at 4:38 laser 1,37613 silver badges14 bronze badges asked Apr 1, 2013 at 0:43 ChaddeusChaddeus 13.4k30 gold badges107 silver badges166 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 11

You need to put an ng-view element in where you want the routeProvider to stick the page's template.

<div ng-app="myApp">
    <div ng-controller="FirstCtrl">
        {{data.message + " world"}}
        <ng-view></ng-view>
    </div>
</div>

Note that indicating it like below keeps you cross-browser pliant.

<div ng-view> </div>

or, for that matter:

<ANY ng-view> </ANY>

More information is available here: http://docs.angularjs/api/ng.directive:ngView

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743715338a4494890.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信