Discussion on some problems of ng-view in angular JS

Source: Internet
Author: User

Statement: This is a discussion of the problem, not to solve the problem, I hope that the more familiar with the friends can see, maybe you can help me

Ng-view is a directive this complements the $route service by including the rendered template of the current route into th E main layout (index.html) file. Every time the current route changes, the included view changes with it according to the configuration of the $route servi Ce.

Above is the angular JS Official document in a section of the description of Ng-view, the general meaning is ng-view this instruction can be routed through the rendered template into the home page display, each time the route changes, the view will be based on the configuration of the route to display the corresponding template content.

The implementation can be written in the same or separate write:

1. Co-write

var ctrls=angular.module ("AAA", [
"Ngroute"
]);
Ctrls.config (function ($routeProvider) {
$routeProvider. When ("/hello", {
Templateurl: "Tpls/hello.html",
Controller: "Helloctrl"
}). When ("/xxx", {
Templateurl: "Tpls/yyy.html",
Controller: "ZZZ"
}). Otherwise ({
Redirectto: "/hello"
});
});
Ctrls.controller (' Helloctrl ', [' $scope ', function ($scope) {
    $scope. hello= "Hello World";
}]);

After testing, the method is feasible.

2. Write separately

App.js:

var app=angular.module ("AAA", [
"Ngroute", "Ctrls"
]);
App. Config (function ($routeProvider) {
$routeProvider. When ("/hello", {
Templateurl: "Tpls/hello.html",
Controller: "Helloctrl"
}). When ("/xxx", {
Templateurl: "Tpls/yyy.html",
Controller: "ZZZ"
}). Otherwise ({
Redirectto: "/hello"
});
});

cntroller.js:
var ctrls=angular.module ("AAA", [
"Ngroute"
]);
Ctrls.controller (' Helloctrl ', [' $scope ', function ($scope) {
    $scope. hello= "Hello World";
}]);

After testing this method did not get the corresponding effect, but also did not error.

If you know the reason, I hope you comment below, thank you very much
I will continue to study and will issue answers to this question later on.

Discussion on some problems of ng-view in angular JS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.