当使用ng-include时,为什么Angular绑定对我不起作用

时间:2015-11-13 00:40:02

标签: angularjs angular-ui-router meanjs

$ scope。$ apply。()也没有帮助,只是产生digest()已经运行的错误。我正在根据州名更改页面标题。它工作正常,标题控制器完成它的工作,但是当加载不同的HtmlTemplate时,它的控制器范围变量不会绑定到它。我有一种感觉,因为我正在替换具有&#39; ng-controller = HeaderController&#39;的import java.util.Scanner; public class More_Grades { public static void main (String [] args) { Scanner scan = new Scanner(System.in); String A = "Your grade is: "; int grade = 0; String y; do { System.out.println("Please Enter Your Grade: "); grade = scan.nextInt(); if (grade < 40) { System.out.println(A+"Fail"); } else if (grade >= 40 && grade <= 49) { System.out.println(A+"3rd"); } else if (grade >= 50 && grade <= 59) { System.out.println(A="2/2"); } else if (grade >= 60 && grade <= 69) { System.out.println(A+"2/1"); } else if (grade >= 70 && grade < 100) { System.out.println(A+"1st"); } else if(grade >100) { System.out.println("Invalid grade,Enter a value below 100."); } System.out.println("Would you like to Enter Another? Y/N"); y = scan.next(); }while (y.equals("yes")); scan.close(); System.out.println("Thank-You."); } 元素的内容。属性,这会导致某种冲突。

的index.html

<header>

header.controller.client.js

<body>
    <header data-ng-controller="HeaderController" data-ng-include="headerUrl"></header>
</body>

PrimaryHeader.view.html

angular.module('core').controller('HeaderController', ['$scope','$state',
    function($scope) {
        function setHeader(stateName) {
            var headerUrl = '';

            switch(stateName) {
                case '': 
                    headerUrl = 'PrimaryHeader.client.view.html';
                    break;
                case 'viewtemplate': 
                    headerUrl = 'HeaderForProductDetails.view.html';
                    break;
                default: 
                    headerUrl = 'PrimaryHeader.client.view.html';
            }

            return headerUrl;
        }

        $scope.headerUrl = setHeader($state.current.name);
    }
]);

HeaderForProductDetails.view.html

<script type="text/ng-template"  id="PrimaryHeader.view.html">
    <h2>
        Hello I am the primary header template and I bind to the HeaderController scope.
    </h2>
    </div>
</script>

headerforproductdetails.controller.client.js

<script type="text/ng-template"  id="HeaderForPrductDetails.view.html">
    <div data-ng-controller="HeaderForPrductDetailsController">
        <h2>
            Hello I am the header for product details and I should be able to bind to my own controller scope and that of my parent. But I don't.
        </h2>


        <div>{{somevalue}}</div> //this scope variable does not bind 
    </div>   
</script>

0 个答案:

没有答案